hdu 1022 hdoj 1022
2011-12-09 09:52
295 查看
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
[align=left]Problem Description[/align]
As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is the fastest all over the world ^v^). But here comes
a problem, there is only one railway where all the trains stop. So all the trains come in from one side and get out from the other side. For this problem, if train A gets into the railway first, and then train B gets into the railway before train A leaves,
train A can't leave until train B leaves. The pictures below figure out the problem. Now the problem for you is, there are at most 9 trains in the station, all the trains has an ID(numbered from 1 to n), the trains get into the railway in an order O1, your
task is to determine whether the trains can get out in an order O2.
[align=left]Input[/align]
The input contains several test cases. Each test case consists of an integer, the number of trains, and two strings, the order of the trains come in:O1, and the order of the trains leave:O2. The input is terminated by the end of file.
More details in the Sample Input.
[align=left]Output[/align]
The output contains a string "No." if you can't exchange O2 to O1, or you should output a line contains "Yes.", and then output your way in exchanging the order(you should output "in" for a train getting into the railway, and "out"
for a train getting out of the railway). Print a line contains "FINISH" after each test case. More details in the Sample Output.
[align=left]Sample Input[/align]
3 123 321
3 123 312
[align=left]Sample Output[/align]
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;
}
}
}
相关文章推荐
- HDOJ HDU 1022 Train Problem I
- HDOJ/HDU 1022 Train Problem I(模拟栈)
- HDOJ/HDU 1022 Train Problem I(模拟栈)
- HDOJ/HDU 2710 Max Factor(素数快速筛选~)
- HDU 1022 Train Problem I(stack)
- HDU 1022 Train Problem I
- hdu 1022 简单栈应用
- HDOJ(HDU) 1408 盐水的故事
- hdu 1022----Train Problem I(栈)
- HDU1022 Train Problem I
- HDOJ (HDU) 1561 The more, The Better (树形DP)
- HDOJ(HDU) 1465 不容易系列之一(错排)
- HDU - 1022 Train Problem I STL 压栈
- HDOJ(HDU).1045 Fire Net (DFS)
- HDOJ(HDU) 1673 Optimal Parking
- HDOJ/HDU 1251 统计难题(字典树啥的~Map水过)
- HDOJ/HDU 3622 二分+2-sat 天津网络赛
- HDOJ(HDU) 1799 循环多少次?(另类杨辉三角)
- HDOJ(HDU).2602 Bone Collector (DP 01背包)
- HDOJ(HDU).2191. 悼念512汶川大地震遇难同胞――珍惜现在,感恩生活 (DP 多重背包+二进制优化)