您的位置:首页 > 大数据 > 人工智能

HDU 1022 ( Train Problem I )

2012-03-24 23:00 423 查看
太囧了,刚开始我居然把

while(!s.empty()) s.pop();

while(!q.empty()) q.pop();

写成了

if(!s.empty()) s.pop();

if(!q.empty()) q.pop();

害我WA了十多次,浪费了不少时间。幸亏在论坛上发帖了,多谢lidajun0717这位兄弟发现了,再次感谢

Problem : 1022 ( Train Problem I )     Judge Status : Accepted
RunId : 5628664    Language : C++    Author : ssun
Code Render Status : Rendered By HDOJ C++ Code Render Version 0.01 Beta

#include<cstdio>
#include<stack>
#include<queue>
#include<string>
#include<iostream>
using namespace std;

int main()
{
stack<char> s;
queue<string> q;
char s1[110],s2[110];
int n;
while(scanf("%d",&n)!= EOF)
{
//getchar();
while(!s.empty()) s.pop();
while(!q.empty()) q.pop();
scanf("%s%s",s1,s2);
//cout<<strlen(s1)<<endl;
//printf("%s\n%s",s1,s2);
int k=0;
int i=0;
while(i<=n)
{
if(!s.empty()&&s.top()==s2[k])
{
while(!s.empty()&&s.top()==s2[k])
{
s.pop();
q.push("out");
k++;
}
if(k>=n) break;
//i--;
}
else if(i==n) break;
else
{
s.push(s1[i]);
q.push("in");
i++;
}
}
if(k>=n)
{   puts("Yes.");
while(!q.empty())
{
cout<<q.front()<<endl;
q.pop();
}
}
else puts("No.");
puts("FINISH");
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: