博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 1022 Train Problem I
阅读量:6380 次
发布时间:2019-06-23

本文共 2428 字,大约阅读时间需要 8 分钟。

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.".
 
都讲STL,是神器,今天我也来试试=。=;这题曾经写过看到网上大家都是一个做法。

果断STL;

#include
#include
#include
#include
#include
#include
using namespace std;const int maxn=110;int main(){ stack
s; int n,i,j,k,r[maxn];//r数组记录的是s1进出栈的情况 char s1[maxn],s2[maxn]; while(cin>>n>>s1>>s2) { i=j=0;k=1; s.push(s1[0]); r[0]=1; while(i

转载地址:http://odqqa.baihongyu.com/

你可能感兴趣的文章
javascript的一些基本概念
查看>>
关于Tomcat上请求的编解码问题
查看>>
WPF“动画序列”框架的初步研究与实现(附源码)
查看>>
Windows Server 2008 多元密码策略配置
查看>>
.NET中的泛型和Java泛型中的类型擦除
查看>>
白利用的集大成者:新型远控木马上演移形换影大法
查看>>
2017必备的八款最佳反勒索软件工具
查看>>
以一当十的程序员不是传说
查看>>
云纵发布“纵横客“ 新一代互联网CRM开启餐饮行业营销新模式
查看>>
物联网到底何时才能称为“爆发”?
查看>>
《Java多线程编程核心技术》——1.2节使用多线程
查看>>
《VMware 网络技术:原理与实践》—— 2.3 OSI模型
查看>>
读书笔记之《实战Java虚拟机》(9):Class 文件结构
查看>>
1024城市峰会 | 当A.I.邂逅古都西安
查看>>
好看的卡片阴影
查看>>
理解 Mach O 并提高程序启动速度
查看>>
Vue实战篇(PC端商城项目)
查看>>
你要做的是产品经理,不是作图经理!
查看>>
JavaEE 项目常见错误汇总
查看>>
快速掌握Python基础语法(下)
查看>>