acm-Train Problem I
来源:互联网 发布:淘宝卖家评价模板 编辑:程序博客网 时间:2024/06/04 07:35
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<cstdio>#include<iostream>#include<stack>using namespace std;int main(){int n;int i,j,k;string a="in",b="out";char first[1001],second[1001];while(scanf("%d %s %s",&n,first,second)!=EOF){stack<char> T;string ch[1001];for(i=0,j=0,k=0;i<n;i++){T.push(first[i]);ch[k++]=a;while(!T.empty()&&T.top()==second[j]){T.pop();j++;ch[k++]=b;}}if(j!=n)printf("No.\n");else{printf("Yes.\n");for(int i=0;i<k;i++)cout<<ch[i]<<endl;}printf("FINISH\n");}return 0;}
- acm-Train Problem I
- ACM-Train Problem I
- 【ACM】杭电1022:Train Problem I
- 杭电ACM 1022 Train Problem I
- 杭电 ACM HDU Train Problem I
- HDU1022 acm 数据结构 Train Problem I
- [ACM] hdu 1022 Train Problem I(栈的使用)
- ACM-栈之Train Problem I——hdu1022
- Java 杭电ACM Train Problem I 1022
- 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
- linux(centos) 常用命令
- OpenCV和PHP的人脸识别技术
- Centos 6.0 yum 更新源
- C语言:快速排序
- 每天定时切割nginx日志的脚本
- acm-Train Problem I
- centos安装nginx+mysql+php+fastcgi+memcache最简单方法
- Nginx下防CC和DDOS攻击
- centos iptables 防火墙 命令
- centos chmod 目录文件权限控制命令
- centos开机启动设置
- nginx的Rewrite实例–在url最后补全/符号
- nginx利用Location,rewrite模块防盗链,禁止访问
- 关于nginx性能优化CPU参数worker_cpu_affinity使用说明