当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

1585:Auto Love-letter Maker

题目描述
As the Valentine's Day is comeing soon, Gardon is anxious about how to write a perfect love-letter to his girlfriend. But because of his poor Emotional quotient, he will never write a perfect love-letter. There is no doubt that roses must come with a love-letter! However, fortunately, Gardon has invented a powerful tool: Auto Love-letter Maker(ALM).
Gardon had spent more than twenty years on ALM though he's only eighteen years old. It follows the principle of GNU General Public License, so we can discover the rules of his algorithm:
1, A love-letter will always be ended with "Love you! yours Gardon". The word "Gardon" is not generated by algorithm.
2, A love-letter will always begin with "Dear Angel".
3, The text of love-letter is generated by some rule called "Markov Words Link". The next word is generated by the last two words.
For example, this ruls is:
dear angel ==> i
angel i ==> miss love wanna
i miss ==> you
i love ==> you
i wanna ==> be
love you ==> for yours
miss you ==> i
you i ==> love
wanna be ==> with
be with ==> you
with you ==> for
you for ==> ever
for ever ==> i love
ever i ==> wanna
ever love ==> you
So we can get this short love-letter:

Dear Angel:
I miss you!I love you for ever!I wanna be with you for ever!
Love you!
Yours, Gardon.

But Gardon find that if he tried to use a rule template which is more complex, it is probable the letter will never stop! After checking the algorithm, he has learned the matter is brought by the Markov rule. So now, he need you help him to check all the words-link template.
输入解释
Input contains serveral words-links rules.each rule begin with a line "**BEGIN**" and end with a line "** END **". each line will contain at least three ,at most thirty words: The first two words represent the rule case, and follow with all the valid words.
You can firmly assume that there will not be more than 10000 differents word in one case. Each word is a string of lower-case letters,and its length will not exceed 20. And I can tell you there is no more than 10000 rules.
输出解释
Output your answer with the following rules:
1. It will NEVER reach the end, or two words which do not exist in the rules's first two words will ALWAYS appear , print "Bad template!".
2. It can POSSIBLY reach the end or two words which do not exist in the rules's first two words MAY appear , print "Imperfect template!".
3. It can ALWAYS reach the end and two words which do not exist in the rules's first two words NEVER appear , print "Perfect template!".
输入样例
**BEGIN**
dear angel i
angel i miss love wanna
i miss you
i love you
i wanna be
love you for yours
miss you i
you i love
wanna be with
be with you
with you for
you for ever
for ever i love
ever i wanna
ever love you
** END **
**BEGIN**
dear angel i
angel i abcd
love you yours
** END **
**BEGIN**
dear angel i
angel i dear
i dear angel
** END **
**BEGIN**
dear angel love
angel love you
love you yours
** END **
输出样例
Imperfect template!
Bad template!
Bad template!
Perfect template!
来自杭电HDUOJ的附加信息
Author DYGG
Recommend linle

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-1585

最后修改于 2020-10-25T22:46:14+00:00 由爬虫自动更新

共提交 99

通过率 77.78%
时间上限 内存上限
1000/5000MS(Java/Others) 32768/65536K(Java/Others)