Train Problem I
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7880 Accepted Submission(s): 2879
3 123 321 3 123 312
Yes. in in in out out out FINISH No. FINISH
#include<stdio.h>
typedef struct Stack
{
int top;
int maze[20];
}Stack;
InitStack(Stack *l)
{
l->top=-1;
}
InStack(int x,Stack *l)
{
l->top++;
l->maze[l->top]=x;
}
OutStack(Stack *l)
{
if(l->top==-1) return;
l->top--;
}
main()
{
int n,i,k,rem[20]={0},p;
Stack l;
char ch1[10],ch2[10];
while(scanf("%d",&n)!=EOF)
{
InitStack(&l);
k=0,p=0;
scanf("%s%s",ch1,ch2);
for (i=0;i<n;i++)
{
InStack(ch1[i],&l);
rem[p]=1;
p++;
while(l.maze[l.top]==ch2[k])
{
OutStack(&l);
p++,k++;
}
}
if(l.top==-1)
{
printf("Yes.\n");
for(i=0;i<2*n;i++)
{
if(rem[i]) printf("in\n");
else printf("out\n");
}
printf("FINISH\n");
}
else printf("No.\nFINISH\n");
for(i=0;i<2*n;i++)
{
rem[i]=0;
}
}
}