64,652
社区成员
发帖
与我相关
我的任务
分享
#include<iostream>
using namespace std;
int x[20],w;
struct stack
{
char data[20];
int top;
}s1;
int initstack(stack &s)
{
s.top=-1;
return 1;
}
int pop(stack &s)
{
x[w++]=0;
return s.data[s.top--];
}
int push(stack &s,int c)
{
s.data[++s.top]=c;
x[w++]=1;
return 1;
}
int isempty(stack s)
{
if(s.top==-1)
return 1;
return 0;
}
int main()
{
int n;
char a[10],b[10];
int j,t;
//initstack(s1); 只做1次初始化将出现“Memory Limit Exceeded”错误
while(scanf("%d",&n)!=EOF)
{
initstack(s1);//移到这里
j=0;
w=0;
t=1;
scanf("%s",a);
scanf("%s",b);
for(int q=0;q<n;q++)
{
if(isempty(s1))
{
push(s1,a[q]);
continue;
}
if(s1.data[s1.top]==b[j])
{
while(!isempty(s1) && s1.data[s1.top]==b[j])//漏判栈非空 while(s1.data[s1.top]==b[j])
{
pop(s1);
j++;
}
push(s1,a[q]);
}
else
push(s1,a[q]);
if(j>n)
break;
}
while(j<n)
{
if(s1.data[s1.top]==b[j])
{
pop(s1);
j++;
}
else
{
t=0;
break;
}
}
if(t==0)
printf("No.\n");
else
{
cout<<"Yes."<<endl;
for(int i=0;i<w;i++)//不是问题,但用w比2*n好。for(int i=0;i<2*n;i++)
if(x[i])
cout<<"in"<<endl;
else
cout<<"out"<<endl;
}
cout<<"FINISH"<<endl;
}
return 0;
}