HDU
来源:互联网 发布:caffe 源码 github 编辑:程序博客网 时间:2024/06/03 04:34
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.
3 123 3213 123 312
Yes.inininoutoutoutFINISHNo.FINISH For the first Sample Input, we let train 1 get in, then train 2 and train 3.So now train 3 is at the top of the railway, so train 3 can leave first, then train 2 and train 1.In the second Sample input, we should let train 3 leave first, so we have to let train 1 get in, then train 2 and train 3.Now we can let train 3 leave.But after that we can't let train 1 leave before train 2, because train 2 is at the top of the railway at the moment.So we output "No.".
#include<iostream>#include<stack>#include<cstdio>using namespace std;int main(){int T;while(scanf("%d",&T)!= EOF){stack<char> s;char sam[1000], train[1000];scanf("%s%s",&train,&sam);int k = 0;for(int i = 0; i < T; ++i){s.push(train[i]);while(!s.empty()&&s.top() == sam[k]){s.pop();++k;}}if(k == T){cout << "Yes." << endl;int j = 0;for(int i = 0; i < T; ++i){s.push(train[i]);cout << "in" << endl;while(!s.empty()&&s.top() == sam[j]){s.pop();cout << "out" << endl;++j;}}}elsecout << "No." << endl;cout << "FINISH" << endl;}}
阅读全文
0 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- 《step1:tiny Spring IoC学习一》——最基本的容器BeanFactory
- Unity3D官方资源包的下载以及从Asset Store下载后存在的位置查找
- HttpServletResponse学习
- 《Java多线程编程核心技术》
- Json
- HDU
- Java中的分层
- Android SDK版本号 与 API Level 对应关系
- java生成图片登录验证码
- HTTPS原理
- 递归问题 文件结构“图” POJ2775
- ssh应用层协议原理 jsch源码探究 authfail
- 我的GIT入门(1)
- HDU