首页 > 代码库 > HDU-1022-Train Problem I

HDU-1022-Train Problem I

题目链接

http://acm.hdu.edu.cn/showproblem.php?pid=1022

模拟栈:

代码

#include<stdio.h>

int main(void)
{
int n,i,j,k,t,r[23],stack[13];
char si[13],so[13];
while(scanf("%d",&n)==1)
{
getchar();
scanf("%s%s",si,so);
r[0]=1; stack[1]=si[0];
j=1; k=1; t=1;
for(i=0;i<n;i++)
{
while(t<n)
{
if(j>0&&stack[j]==so[i])
{
j--;
r[k++]=2;
break;
}
stack[++j]=si[t++];
r[k++]=1;
}
if(stack[j]==so[i])
{
j--;
r[k++]=2;
}
}
n=n*2;
if(k<n)
printf("No.\n");
else
{
printf("Yes.\n");
for(i=0;i<k;i++)
{
switch(r[i])
{
case 1:printf("in\n"); break;
case 2:printf("out\n"); break;
}
}
}
printf("FINISH\n");
}
return 0;
}

HDU-1022-Train Problem I