HDU 1022 之 Train Problem I
Train Problem I
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 21736 Accepted Submission(s): 8232
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.



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.
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 312
in
in
in
out
out
out
FINISH
No.
FINISH
Hint
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 <cstdio>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <queue>
#include <stack> using namespace std; int main()
{
int n;
int i, j, k;
char s[1000], t[1000];
char dd, ff; char map[1000][5]; int e=0; while(scanf("%d", &n)!=EOF)
{
stack<char>q;
stack<char>p; memset(map, '\0', sizeof(map)); scanf("%s", s);
scanf("%s", t); for(j=n-1; j>=0; j--)
{
p.push(t[j]);
} e=0; for(i=0; i<n; i++)
{
q.push(s[i]);
//cout<<s[i]<<"*"<<endl;
strcat(map[e++], "in"); dd=q.top(); ff=p.top();
while( dd==ff && !q.empty() && !p.empty() )
{
strcpy(map[e++], "out");
q.pop();
if(!q.empty()) dd=q.top();
p.pop();
if(!p.empty()) ff=p.top();
}
}
if(q.empty() && p.empty() )
{
cout<<"Yes.\n";
for(k=0; k<e; k++)
{
cout<<map[k]<<endl;
}
}
else
{
cout<<"No.\n";
}
cout<<"FINISH\n";
}
return 0;
}
HDU 1022 之 Train Problem I的更多相关文章
- HDU——1023 Train Problem II
Train Problem II Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1022 Train Problem I
A - Train Problem I Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- HDU 1022 Train Problem I(栈的操作规则)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1022 Train Problem I Time Limit: 2000/1000 MS (Java/Ot ...
- hdu 1022 Train Problem I【模拟出入栈】
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- Hdu 1022 Train Problem I 栈
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1022.Train Problem I【栈的应用】【8月19】
Train Problem I Problem Description As the new term comes, the Ignatius Train Station is very busy n ...
- HDU - 1022 Train Problem I STL 压栈
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1022 Train Problem I(栈的应用+STL)
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1022:Train Problem I(数据结构,栈,递归,dfs)
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
随机推荐
- 解决mybatis xml文件代码提示
今天在开源项目社区看到一个插件挺不错的,推荐给大家.叫MyBatis MyBatis 是一个流行的 Java 数据持久层框架.MyBatipse 是一个 Eclipse 插件,在编辑 MyBatis ...
- tyvj 1432 楼兰图腾
树状数组 本题数据有误 对于每一个点用权值树状数组维护在这个点之后之前的比他大和比他小的数 #include <iostream> #include <cstdio> #inc ...
- 2017 ACM/ICPC Asia Regional Xian Online 记录
题目链接 Xian
- windows安装RabbitMQ注意事项
1.首先下载好ERLANG.RabbitMQ安装包,先安装erlang,设置好环境变量,然后再去安装MQ; 2.别人有两个报错: 一:RabbitMQ安装目录中不允许有空格; 二:安装rabbitmq ...
- CodeWar----求正整数二进制表示中1的个数
Codewars Write a function that takes an integer as input, and returns the number of bits that are eq ...
- Ubuntu 16.04安装微信
微信没有出Linux的版本,但是可以通过以下方式解决: 1.使用网页版,除了没有公众号之后,一切都没问题,包括传文件等. 网页登录地址:https://wx.qq.com/ 2.使用第三方版本,只不过 ...
- 【Vue 学习系列 - 01】- 环境搭建(Win7)
1. 根据系统下载Node.js 下载地址:http://nodejs.cn/download 2. 安装Node.js 点击安装Node.js,在安装目录D:\Program Files\nodej ...
- annotation使用示例
annotation使用示例 学习了:https://www.imooc.com/learn/456 Annotation编写规则:@Target,@Retention,设置一些String.int属 ...
- 用C++实现一个Log系统
提要 近期在写一些C++的图形代码,在调试和測试过程中都会须要在终端打印一些信息出来. 之前的做法是直接用 std::cout<<"Some Word"<< ...
- Json实现异步请求(提交评论)
主要将代码粘贴,通过阅读代码理解当中的相关逻辑. html代码: <form id="form1" runat="server"> <p> ...