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

hdu 1022 Train Problem I

2015-04-27 19:43 405 查看
栈的应用,一定要注意把栈清空啊,最近刚开始学数据结构,代码有点水,大家不要见怪

#include<iostream>
#include<stack>
using namespace std;
int main()
{
int n;
string in,out;
stack<int>root;
while(cin>>n>>in>>out)
{
while(root.size()) root.pop();
string re="";
for(int i=0;i<in.size();i++)
{
root.push(in[i]-'0');
re+='1';
while(root.size()&&root.top()==out[0]-'0')
{
root.pop();
out.erase(0,1);
re+='2';
}
}
if(root.empty())
{
cout<<"Yes."<<endl;
for(int i=0;i<re.size();i++)
{
if(re[i]=='1') cout<<"in"<<endl;
else cout<<"out"<<endl;
}
cout<<"FINISH"<<endl;
}
else  cout<<"No."<<endl<<"FINISH"<<endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: