Train Problem I

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 16859    Accepted Submission(s): 6300

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
 
栈的应用....
何为栈.....像一个瓶子....同一端进,同一端出....
//用到的头文件
#include<stack>
//声明
stack<type> s; s.push() ; //入栈;
s.top() ; //提起顶端元素
s.pop() ; //删除顶端元素
s.empty() ; //判断是否为空
s.size() ; // 栈的大小

此题纯属模拟即可轻松过....

代码:

 #include<iostream>
#include<cstdio>
#include<stack>
using namespace std;
int main()
{
int n,i;
while(cin>>n)
{ stack<char> s;
bool c[];
int rank=,step=;
char a[],b[];
scanf("%s %s",b,a);
for(i=;i<n;i++)
{
if(a[rank]==b[i])
{
/*false---》进栈,true---》出栈*/
c[step++]=false;
c[step++]=true;
rank++;
}
else
{
while(!s.empty())
{
if(a[rank]==s.top())
{
rank++;
s.pop();
c[step++]=true;
}
else break;
}
s.push(b[i]);
c[step++]=false;
}
}
while(rank<n&&a[rank]==s.top())
{
rank++;
s.pop();
c[step++]=true;
}
if(!s.empty())
{
printf("No.\n");
}
else
{
puts("Yes.");
for(i=;i<*n;i++)
{
if(c[i])
puts("out");
else
puts("in");
}
}
puts("FINISH");
}
return ;
}

HDUOJ-------(1022)Train Problem I的更多相关文章

  1. (stack)Train Problem I hdu1022

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  2. (母函数 Catalan数 大数乘法 大数除法) Train Problem II hdu1023

    Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  3. HDU 1022 之 Train Problem I

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  4. 2016中国大学生程序设计竞赛(长春) Ugly Problem 模拟+大数减法

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5920 我们的思路是: 对于一个串s,先根据s串前一半复制到后一半构成一个回文串, 如果这个回文串比s小, ...

  5. 形式化验证工具(PAT)Reader-Writers Problem学习

    经过前几次的学习,我们应该对PAT有一点点的了解了,我们加下来就直接看例子中的一个问题,这个问题比较简单. 看代码: //The classic Readers/Writers Example mod ...

  6. (算法)Hanoi Problem汉诺塔问题

    Problem: There are three poles and N disks where each disk is heaver than the next disk. In the init ...

  7. Caffe初试(三)使用caffe的cifar10网络模型训练自己的图片数据

    由于我涉及一个车牌识别系统的项目,计划使用深度学习库caffe对车牌字符进行识别.刚开始接触caffe,打算先将示例中的每个网络模型都拿出来用用,当然这样暴力的使用是不会有好结果的- -||| ,所以 ...

  8. LARC Caffe笔记(二) 训练自己的img

    继看完 贺完结!CS231n官方笔记 上一次已经成功跑起caffe自带的例程,mnist和cifar10 但是终归用的是里面写好的脚本,于是打算训练自己的img 〇.目标 准备好food图片3类(出于 ...

  9. CAFFE学习笔记(五)用caffe跑自己的jpg数据

    1 收集自己的数据 1-1 我的训练集与测试集的来源:表情包 由于网上一幅一幅图片下载非常麻烦,所以我干脆下载了两个eif表情包.同一个表情包里的图像都有很强的相似性,因此可以当成一类图像来使用.下载 ...

随机推荐

  1. 如何判断某版本的.NET Framework是否安装

    1..NET Framework .NET Framework2.0    键:[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\N ...

  2. Leader之重

    1:合理安排每个CASE并检查每个人每天的工作进度和质量: 这会让一个庞大的工作,或者看上不可能完成的任务,变成可完成的.   2:警惕对立情绪,并寻找交接者: 永远无法控制所有成员对你或者对团队对公 ...

  3. Grunt常见问题

    1.nodeJs 环境安装?进入官网:http://www.nodejs.org/ 根据操作系统,下载相应的安装包,直接安装即可. 2.npm 安装?a) 如果系统没有安装过Git,可以直接到http ...

  4. html 制作复杂table

    数据分析,一般都需要显示数据,就需要使用html做复杂的表格.复杂表格一般是对td的rowspan .colspan属性值. 在html中<td> 标签定义 HTML 表格中的标准单元格. ...

  5. 分布式唯一ID极简教程

    原创 2017-11-21 帝都羊 架构师小秘圈 一,题记 所有的业务系统,都有生成ID的需求,如订单id,商品id,文章ID等.这个ID会是数据库中的唯一主键,在它上面会建立聚集索引! ID生成的核 ...

  6. IE9对HTML5中一部分属性不提供支持的原因

    为什么在IE9中对于HTML5标准中的离线应用程序以及CSS3中的一部分不提供支持?笔者间接了解到了这个原因. 微软日前已经发布了Internet Explorer 9(以下简称IE9)正式版.在该版 ...

  7. 理解闭包的微观世界和JS垃圾回收机制

    function a() { ; function b() { alert(++i); } return b; } var c = a(); c(); 一.闭包的微观世界 如果要更加深入的了解闭包以及 ...

  8. SqlServer 在查询结果中如何过滤掉重复数据

    问题背景 在一个多表查询的sql中正常情况下产生的数据都是唯一的,但因为数据库中存在错误(某张表中存在相同的外键ID)导致我这边查询出来的数据就会有重复的问题 下面结果集中UserID:15834存在 ...

  9. json树递归js查询json父子节点

    上代码,直接另存为html打开,看console控制台就可以看到效果了 <!DOCTYPE html> <html lang="en"> <head& ...

  10. [Backbone]6. Collections.

    Define a collection: var AppointmentList = Backbone.Collection.extend({model: Appointment}); RESET t ...