现在的位置: 首页 > 综合 > 正文

http://acm.nyist.net/JudgeOnline/problem.php?pid=150

2013年08月09日 ⁄ 综合 ⁄ 共 463字 ⁄ 字号 评论关闭

栈的应用水题,,

#include<string>
#include<stack>
#include<string.h>
#include<iostream>
using namespace std;
string a[20];
int main()
{
	int n;
	string s,s1;
	while(cin>>n)
	{  stack<char> Q;
		cin>>s>>s1;
		int i=0,j=0;
		int tot=0;
		bool ok=0;
		while(j<n)
		{
			if(!Q.empty()&&Q.top()==s1[j])
			{  a[++tot]="out";
				Q.pop();j++;
			}
			else if(i<n) {
			
				Q.push(s[i++]);
				a[++tot]="in";
			}
			else {ok=1;break;}
       }
		if(ok) cout<<"No."<<endl<<"FINISH"<<endl;
		else{
			cout<<"Yes."<<endl;
			for(int i=1;i<=tot;++i)
				cout<<a[i]<<endl;
			cout<<"FINISH"<<endl;
		}
	}return 0;
}

抱歉!评论已关闭.