就是一道考栈结构运用的题,挺简单的,用一个栈模拟火车的出入就行了。
代码如下:
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
const int M=1010;
const int N=100010;
int n;
char s1[N],s2[N];
int main()
{
int i,j;
while(~scanf("%d%s%s",&n,s1,s2))
{
char s[N];
int k=-1,e=0,j=0,a[N];
for (i=0;i<n;i++){
s[++k]=s1[i]; // 序列s1中的元素入栈
a[e++]=1;
while(s[k]==s2[j]){ // 若栈顶元素与序列s2中的相同,出栈
a[e++]=0;
k--;
j++;
if (k==-1) break;
}
}
if (k==-1){
puts("Yes.");
for (i=0;i<e;i++)
if (a[i]) puts("in");
else puts("out");
}
else puts("No.");
puts("FINISH");
}
}