序列Q1,请过堆栈的一系列的操作(push和pop),能否变成序列Q2,能的话输出操作顺序
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include <iostream>
#include<queue>
#include<stack>
#include<string>
using namespace std;
string ans[20000];
int num = 0;
int main()
{
int t;
while(cin>>t)
{
string in;
string out;
stack<char> s;
cin>>in>>out;
int i=0;
int j=0;
num = 0;
int ok = 1;
while(j<t)
{
if(s.empty())
{
if(i<t)
{
s.push(in[i++]);
ans[num++] = "in";
}
else
{
ok = 0;
break;
}
}
if(s.top()!=out[j])
{
if(i<t)
{
s.push(in[i++]);
ans[num++] = "in";
}
else
{
ok = 0;
break;
}
}
else
{
ans[num++] = "out";
s.pop();
j++;
}
}
if(ok)
{
cout<<"Yes.\n";
for(int i=0;i<num;i++)
{
cout<<ans[i]<<endl;
}
}
else
cout<<"No.\n";
cout<<"FINISH\n";
}
}