Train Problem I

#include <iostream>
#include <string>
#include <stack>
using namespace std;
stack<char> s;
bool ans[100000];
int main()
{
int n;
string in,out;
while(cin>>n>>in>>out)
{
int id = 0,pos = 0;
while(!s.empty()) s.pop();
for(int i=0;i<n;i++)
{
s.push(in[i]);
ans[++id] = true;
while(!s.empty() && out[pos]==s.top())
{
ans[++id] = false;
s.pop();
pos++;
}
}
for(int i=pos;i<n;i++)
{
if(!s.empty() && out[i]==s.top())
{
ans[++id] = false;
s.pop();
}
else break;
}
if(id==2*n)
{
cout << "Yes." << endl;
for(int i=1;i<=id;i++)
if(ans[i]) cout << "in" << endl;
else cout << "out" << endl;
}
else cout <<"No." << endl;
cout << "FINISH" << endl;
}
return 0;
}

猜你喜欢

转载自www.cnblogs.com/zmhdbk/p/9277267.html