正文

10142006-06-09 16:28:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/bakers/15619.html

分享到:

变形课 Time Limit:1000MS  Memory Limit:65536KTotal Submit:44 Accepted:11 Description 呃......变形课上Harry碰到了一点小麻烦,因为他并不像Hermione那样能够记住所有的咒语而随意的将一个棒球变成刺猬什么的,但是他发现了变形咒语的一个统一规律:如果咒语是以字母a开头和以字母b结尾的一个单词,那么它的作用就恰好是使A物体变成B物体。譬如,一个咒语bright可以把一个B物体变成T。 Harry已经将他所会的所有咒语都列成了一个表,他想让你帮忙计算一下他是否能完成老师的作业,将一个B(ball)变成一个M(Mouse),你知道,如果他自己不能完成的话,他就只好向Hermione请教,并且被迫听一大堆好好学习的道理. Input 每行一个单词,仅包括小写字母,是Harry所会的所有咒语. Output 如果Harry可以完成他的作业,就输出"Yes.",否则就输出"No."(不要忽略了句号) Sample Input so soon river goes them got moon begin big Sample Output Yes. Hint Harry 可以念这个咒语:"big-got-them".     Source #include"iostream" #include"string" #include"stack" #include"vector" using namespace std; stack<string>sta; vector<string>str; int found=0; bool chan() { int i,j; for(i=0;i<str.size();) { if(str[i][0]=='b') { sta.push(str[i]); str.erase(str.begin()+i); if(sta.top()[sta.top().size()-1]=='m')return true; } else i++; } while(sta.size()>=1&&!str.empty()) { found=0; for(i=0;i<str.size();) if(str[i][0]==sta.top()[sta.top().size()-1]) { sta.push(str[i]); if(str[i][str[i].size()-1]=='m')return true; str.erase(str.begin()+i); found=1; } else i++; if(found==0)sta.pop(); } return false; } int main() { int i=0,j=0; string s; while(cin>>s) str.push_back(s); if(chan())cout<<"Yes."; else cout<<"No."; return 1; }

阅读(4983) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册