Train Problem I
2009-10-11 20:15
176 查看
简单题,模拟栈的操作。
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 10000
int main()
{
int n,t1,t2,i,j,k;
char s1
,s2
[4],x
,y
;
while(scanf("%d%s%s",&n,x,y)!=EOF)
{
t1=-1;k=j=0;
for(i=0;x[i];i++)
{
s1[++t1]=x[i];
strcpy(s2[k++],"in");
if(s1[t1]==y[j])
{
while(y[j] && t1>=0 && y[j]==s1[t1])
{
t1--;
j++;
strcpy(s2[k++],"out");
}
}
}
if(t1!=-1) {
printf("No.\nFINISH\n");
}
else
{
printf("Yes.\n");
for(i=0;i<k;i++)
printf("%s\n",s2[i]);
printf("FINISH\n");
}
}
return 0;
}
本文来源于网络小筑 http://www.iwebtrados.com.cn/ , 原文地址:http://www.iwebtrados.com.cn/post/230.html
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 10000
int main()
{
int n,t1,t2,i,j,k;
char s1
,s2
[4],x
,y
;
while(scanf("%d%s%s",&n,x,y)!=EOF)
{
t1=-1;k=j=0;
for(i=0;x[i];i++)
{
s1[++t1]=x[i];
strcpy(s2[k++],"in");
if(s1[t1]==y[j])
{
while(y[j] && t1>=0 && y[j]==s1[t1])
{
t1--;
j++;
strcpy(s2[k++],"out");
}
}
}
if(t1!=-1) {
printf("No.\nFINISH\n");
}
else
{
printf("Yes.\n");
for(i=0;i<k;i++)
printf("%s\n",s2[i]);
printf("FINISH\n");
}
}
return 0;
}
本文来源于网络小筑 http://www.iwebtrados.com.cn/ , 原文地址:http://www.iwebtrados.com.cn/post/230.html
相关文章推荐
- hdu 1022 Train Problem I
- HDOJ1022 Train Problem I 栈模拟
- HDU Train Problem I (STL_栈)
- Train Problem I--hdu1022(栈)
- hdu1022 Train Problem I
- Train Problem I
- 杭电ACM OJ 1022 Train Problem I 回溯法求出栈遍历序列 很强大
- HDU 1022 Train Problem I
- 606第三周周六赛C - Train Problem I
- 杭电OJ--1021 Train Problem I
- Train Problem I
- hdu 1023 Train Problem II【卡特兰数】
- 【ACM】杭电1022:Train Problem I
- HDU 1023 Train Problem II
- HDOJ P1022 Train Problem I
- 【杭电】[1022]Train Problem I
- hdu 1022 Train Problem I
- Train Problem I
- hdu-1022 Train Problem I (栈的简单应用)
- 1022:Train Problem I