NYOJ150 Train Problem I 【栈】
来源:互联网 发布:淘宝服饰鞋包包括哪些 编辑:程序博客网 时间:2024/05/29 15:12
Train Problem I
时间限制:3000 ms | 内存限制:65535 KB
难度:2
- 描述
- 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.
- 输入
- 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.
- 输出
- 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.
- 样例输入
3 123 3213 123 312
- 样例输出
Yes.inininoutoutoutFINISHNo.FINISH
#include <stdio.h>#include <string.h>char tin[11], tout[11], stack[11], *sign[] = {"in", "out"};int op[22];int main(){int num, idin, idout, idop, id;while(scanf("%d%s%s", &num, tin, tout) == 3){idin = idout = 0;idop = id = 0;while(idin < num && idout < num){stack[id++] = tin[idin++];op[idop++] = 0;while(id && stack[id-1] == tout[idout]){ op[idop++] = 1; --id; ++idout; }}if(id == 0){puts("Yes.");for(int i = 0; i < idop; ++i) puts(sign[op[i]]);puts("FINISH");}else puts("No.\nFINISH");}return 0;}
0 0
- NYOJ150 Train Problem I 【栈】
- Train Problem I 栈
- hdoj1022------------------Train Problem I---栈
- Train Problem I(栈)
- hdu Train Problem I (栈 )
- Train Problem I(栈)
- HDU1022--Train Problem I(栈)
- hdu 1022 Train Problem I 栈
- Train Problem I hdu 1022 栈
- hdu 1022 Train Problem I(栈)
- hdu 1022 Train problem I(栈~~)
- NYOJ 150 Train Problem I 【栈】
- HDOJ1022 Train Problem I 栈模拟
- HDU 1022 Train Problem I 栈、队列
- NYOJ 150 Train Problem I STL栈
- hdu 1022 Train Problem I(栈)
- HDU 1022 Train Problem I (栈)
- Train Problem I(栈和队列)
- c# 中如何操作消息队列
- Anroid下TabHost布局
- 第12周项目二
- 设置控件的透明度 ,android:layout_centerInParent="true" 失效
- win7下安装oracle 11g
- NYOJ150 Train Problem I 【栈】
- 基于TDI的网络防火墙
- hadoop中使用MapReduce编程实例
- PHP网站备份程序代码分享
- linux常用命令
- 小白鼠与毒药解题过程分析
- 利用IPC通道进行进程间通信(C#)
- javascript数组的使用
- leetcode第一刷_Divide Two Integers