Train Problem I

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 38390    Accepted Submission(s): 14423

Problem Description
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.

 
Input
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.
 
Output
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.
 
Sample Input
3 123 321
3 123 312
 
Sample Output
Yes.
in
in
in
out
out
out
FINISH
No.
FINISH
Hint
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.".
 
Author
Ignatius.L
Problem : 1022 ( Train Problem I )     Judge Status : Accepted

RunId : 21242780    Language : G++    Author : hnustwanghe

Code Render Status : Rendered By HDOJ G++ Code Render Version 0.01 Beta

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<stack>

using namespace std;

int main(){
int n;
while(scanf("%d",&n)==1){
if(n == 0){
printf("Yes.\nFINISH\n");
continue;
}
stack<int> S;
string O1,O2;
cin >> O1 >> O2;
int pos = 0;
int a[50],cur = 0;
for(int i=0;i<O1.length();i++){
S.push(O1[i]-'0');
a[cur++] = 1;///入栈
while(!S.empty() && S.top()== O2[pos]-'0' && pos <O2.length()){
S.pop();
pos++;
a[cur++] = 2;///出栈
}
}
if(pos == O2.length() && S.empty()){
printf("Yes.\n");
for(int i=0;i<cur;i++){
printf("%s\n",a[i]<2?"in":"out");
}
printf("FINISH\n");
}
else
printf("No.\nFINISH\n");
}
}

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<stack>

using namespace
std; int main(){
int
n;
while(
scanf("%d",&n)==1){
if(
n == 0){
printf("Yes.\nFINISH\n");
continue;
}

stack<int> S;
string O1,O2;
cin >> O1 >> O2;
int
pos = 0;
int
a[50],cur = 0;
for(int
i=0;i<O1.length();i++){
S.push(O1[i]-'0');
a[cur++] = 1;///入栈
while(!S.empty() && S.top()== O2[pos]-'0' && pos <O2.length()){
S.pop();
pos++;
a[cur++] = 2;///出栈
}
}
if(
pos == O2.length() && S.empty()){
printf("Yes.\n");
for(int
i=0;i<cur;i++){
printf("%s\n",a[i]<2?"in":"out");
}

printf("FINISH\n");
}
else

printf("No.\nFINISH\n");
}
}

思维体操: HDU1022Train Problem I的更多相关文章

  1. HDU-1022Train Problem I,简单栈模拟;

    Train Problem I                                                                                     ...

  2. HDU1022--Train Problem I(栈的应用)

    Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot o ...

  3. 思维体操: HDU1287破译密码

    破译密码 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  4. 思维体操: HDU1049Climbing Worm

    Climbing Worm Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) To ...

  5. 思维体操: HDU1008 Elevator

    Elevator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total S ...

  6. 并查集+思维——The Door Problem

    一.问题描述(题目链接) 有n个门和m个开关,每个开关可以控制任意多的门,每个门严格的只有两个开关控制,问能否通过操作某些开关使得所有门都打开.(给出门的初始状态). 二.问题分析 大部分开关问题首先 ...

  7. 2018-2019 ACM-ICPC, Asia Xuzhou Regional Contest- H. Rikka with A Long Colour Palette -思维+贪心

    2018-2019 ACM-ICPC, Asia Xuzhou Regional Contest- H. Rikka with A Long Colour Palette -思维+贪心 [Proble ...

  8. 2.Web开发过程流程图

    转自:https://blog.csdn.net/hello_simon/article/details/19993343 最近公司在进行一系列新模块的开发,在痛苦开发的过程中,大家不时在一起进行总结 ...

  9. 题解-Koishi Loves Construction

    题解-Koishi Loves Construction 前缀知识 质数 逆元 暴搜 Koishi Loves Construction 给定 \(X\),\(T\) 组测试数据,每次给一个 \(n\ ...

随机推荐

  1. 导出csv文件(使用a标签)

    https://blog.csdn.net/oscar999/article/details/16342699   productsCSV(e) { const { download } = this ...

  2. Linux安装vsftpd及配置详解

    1 安装vsftpd组件 安装完后,有/etc/vsftpd/vsftpd.conf 文件,是vsftp的配置文件.[root@bogon ~]# yum -y install vsftpd 2.FT ...

  3. nginx下的负载均衡

    负载均衡应用场景: 普通web应用部署到多台应用服务器上,客户端通过访问应用服务器发送请求,最简单的就是n对1模式,n个客户端访问同一个应用服务器,这种情况当并发量大了,就无法应对,而且,如果只有一台 ...

  4. 第五周学习总结&实验报告(三)

    第五周学习总结&实验报告(三) 这一周又学习了新的知识点--继承. 一.继承的基本概念是: *定义一个类,在接下来所定义的类里面如果定义的属性与第一个类里面所拥有的属性一样,那么我们在此就不需 ...

  5. 第三周总结&实验报告一

    第三周总结 在这周对Java进行了更深层次的学习,Java的学习也越来越难了,慢慢的加入了一些新的构造新的方法,还有许许多多简化代码的相关知识,我还是要认真的去吃透这些知识,自己也要慢慢的去研究一些题 ...

  6. Maven中的dependency详解

    <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> & ...

  7. 在WCF程序中动态修改app.config配置文件

    今天在个WCF程序中加入了修改配置文件的功能.我是直接通过IO操作修改的app.config文件内容,修改后发现发现其并不生效,用Google搜了一下,在园子里的文章动态修改App.Config 和w ...

  8. Python Module_pdb_DEBUG 方法

    目录 目录 pdb pdb 的 Debug 方式 pdb 的调试指令 示例 IPython 自带的 Debug 工具 ipdb pdb pdb 是 Python 自带的程序包,为 Python 程序提 ...

  9. 【Spring】---【AOP】

    转发几篇文章 专治不会看源码的毛病--spring源码解析AOP篇 Spring3:AOP 理解AOP 什么是AOP? 转自: http://www.cnblogs.com/xiexj/p/73668 ...

  10. flultter listview异常type '(BuildContext, int) => dynamic' is not a subtype of type '(BuildContext, int) => Widget'

    type '(BuildContext, int) => dynamic' is not a subtype of type '(BuildContext, int) => Widget' ...