网站设计思路方案,wordpress yii,广州建站公司模板,wordpress微信群导航模板Description 呃......变形课上Harry碰到了一点小麻烦,因为他并不像Hermione那样能够记住所有的咒语而随意的将一个棒球变成刺猬什么的,但是他发现了变形咒语的一个统一规律:如果咒语是以a开头b结尾的一个单词,那么它的作用就恰好是使A物体变成B物体. Harry已经将他所会的所有咒… Description 呃......变形课上Harry碰到了一点小麻烦,因为他并不像Hermione那样能够记住所有的咒语而随意的将一个棒球变成刺猬什么的,但是他发现了变形咒语的一个统一规律:如果咒语是以a开头b结尾的一个单词,那么它的作用就恰好是使A物体变成B物体. Harry已经将他所会的所有咒语都列成了一个表,他想让你帮忙计算一下他是否能完成老师的作业,将一个B(ball)变成一个M(Mouse),你知道,如果他自己不能完成的话,他就只好向Hermione请教,并且被迫听一大堆好好学习的道理. Input 测试数据有多组。每组有多行每行一个单词,仅包括小写字母,是Harry所会的所有咒语.数字0表示一组输入结束. Output 如果Harry可以完成他的作业,就输出Yes.,否则就输出No.(不要忽略了句号) Sample Input so
soon
river
goes
them
got
moon
begin
big
0 Sample Output Yes. Hint Hint Harry 可以念这个咒语:big-got-them. 代码利用队列可解 #includecstdio #includecstring #includealgorithm #includequeue #includeiostream using namespace std; const int Max1500; struct node { char top; char rear; }a[Max]; int used[Max]; int main() { char ch[Max]; node b; queuestruct nodeq; while(cinch) { memset(used,0,sizeof(used)); int len,i0; if(ch[0]!0) { a[i].topch[0]; lenstrlen(ch); a[i].rearch[len-1]; i; } while(cinch) { if(ch[0]!0) { lenstrlen(ch); a[i].topch[0]; a[i].rearch[len-1]; i; } else break; } for(int j0;ji;j) { if(a[j].topb) { used[j]1; q.push(a[j]);//jinzhan } } while(!q.empty()) { bq.front(); q.pop(); if(b.rearm) { coutYes.endl; break; } else { for(int j0;ji;j) { if(a[j].topb.rear!used[j]) { used[j]1; q.push(a[j]); } } } } if(b.rear!m) { coutNo.endl; } } }