NYOJ 150 Train Problem I
来源:互联网 发布:csi网络犯罪第一季 编辑:程序博客网 时间:2024/05/18 03:15
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
- 来源
- POE_Crazy
- 上传者
张洁烽
#include<stdio.h>#include<string.h>#include<stack>using namespace std;int main(){int n,c[22],l,k,i;char a[22],b[22];while(~scanf("%d",&n)){l=0;k=0; memset(c,0,sizeof(c)); stack<char>s; while(!s.empty()) s.pop(); scanf("%s%s",a,b); for(i=0;i<n;i++) {s.push(a[i]); c[l++]=1; while(!s.empty()&&s.top()==b[k]) { s.pop(); k++; c[l++]=2; } } if(s.empty()) {printf("Yes.\n"); for(i=0;i<l;i++) if(c[i]==1) printf("in\n"); else printf("out\n"); } else printf("No.\n"); printf("FINISH\n");}}
0 0
- NYOJ 150 Train Problem I
- NYOJ---150题Train Problem I
- NYOJ 150 Train Problem I 【栈】
- NYOJ 150 Train Problem I STL栈
- hdu-1022-train problem I-----nyoj-150
- hpu 1022&&nyoj 150 Train Problem I 【栈】
- 1022 Train Problem I
- HDU1022 Train Problem I
- Train Problem I
- 1022:Train Problem I
- 1022 Train Problem I
- HDU1022 Train Problem I
- Train Problem I
- HDU1022:Train Problem I
- HDU1022--Train Problem I
- Train Problem I
- hdu1022-Train Problem I
- HDU1022 Train Problem I
- android 4.4 Launcher2源码分析--Workspace滑动
- OpenGL动态曲线的实现
- 换钱的方法数
- 批处理逻辑+sql语句+xls输出+bigDecimal
- ACM为啥子这么难?怎么才能搞好它?
- NYOJ 150 Train Problem I
- linux上文件格式引起的问题
- POJ 1080 LCS变式dp
- 单例模式(防继承,防克隆)
- Oracle11gR2的安装和卸载
- UNIX学习笔记----makefile之条件判断
- SQL数据库查询-Select
- 接口(interface)
- angularJS学习之路(四)---作用域(1)