HDU - 1022 Train Problem I
#include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
int n;
string a[101],s1,s2;
int main()
{
while(scanf("%d",&n)!=EOF)
{
stack<char>s;
int j=0,p=0;
cin>>s1>>s2;
for(int i=0;i<n;i++)
{
s.push(s1[i]);//进栈
a[p++]="in";
while(!s.empty()&&s.top()==s2[j])//判断刚进栈的元素是否和序列相同
{
a[p++]="out";
s.pop();
j++;
}
}
if(s.empty())//栈为空说明能够满足条件
{
cout<<"Yes."<<endl;
for(int i=0;i<p;i++)
cout<<a[i]<<endl;
cout<<"FINISH"<<endl;
}
else
{
cout<<"No."<<endl;
cout<<"FINISH"<<endl;
}
}
return 0;
}