首页 > 其他 > 详细

hdu 1022 Train Problem I

时间:2015-04-27 21:55:39      阅读:213      评论:0      收藏:0      [点我收藏+]

栈的应用,一定要注意把栈清空啊,最近刚开始学数据结构,代码有点水,大家不要见怪

#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;
}


hdu 1022 Train Problem I

原文:http://blog.csdn.net/zafkiel_nightmare/article/details/45314731

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!