64,282
社区成员
发帖
与我相关
我的任务
分享
/*1022 Train Problem I*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
bool or[30];
void prin(int l)
{
int i;
puts("YES.");
for(i=0;i<l*2;i++){
if(or[i])
printf("in\n");
else printf("out\n");
}
printf("FINISH\n");
}
void prin1()
{
printf("NO.\nFINISH\n");
}
int main()
{
char a[15],b[15];
char stack[15];
int n;
int i,j,k,len;
char *top,*base;
bool flag;
while(scanf("%d",&n)==1){
if(!n) continue;
scanf("%s %s",a,b);
len = strlen(b);
top=base=stack;
i=j=k=0; flag=true;
while(i<len){
if(top==base) {
*top=a[k++];or[j++]=true;
top++;
}//如果是空栈,进一个
if(*(b+i)==*(top-1)){
top--;or[j++]=false;
i++;
}//如果将要出站车,为栈顶元素,出栈
else{
*top=a[k++];or[j++]=true;
top++;
}//不是,入栈
if(top-base>len){//如果栈大于车数,证明不可以以这样顺序
flag=false;
break;
}
}
if(flag) prin(len);
else prin1();
getchar();
}
return 0;
}