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. hadoop基准測试

    写測试hadoop jarhadoop-0.20.2-test.jar TestDFSIO -write -nrFiles 10 -fileSize 1000 ----- TestDFSIO ---- ...

  2. Android -- Drawable && Bitmap

    Bitmap转Drawable Bitmap bm=xxx; BitmapDrawable bd=new BitmapDrawable(bm); 因为BtimapDrawable是Drawable的子 ...

  3. EOSS V3.0 企业运营支撑系统(基于RBAC原理的权限管理)

    一:EOSS 功能介绍 其于用户,角色,权限,菜单的一套“简约实用”的权限管理系统,可在其基础之上,快速进行二次开发. 一个用户可以选择多个角色. 一个角色可以选择多个权限. 一个菜单可以有无限级子菜 ...

  4. 在CentOS/RHEL上设置SSH免密码登录

    本文会告诉你怎样在 CentOS/RHEL 上设置 SSH 免密码登录.自动登录配置好以后,你可以通过它使用 SSH (Secure Shell)和安全复制 (SCP)来移动文件. SSH 是开源的, ...

  5. C++的基本类型

  6. [Node.js]25. Level 5. Route params

    Create a route that responds to a GET request '/quotes/<name>', then use the param from the UR ...

  7. Jmeter测试报告可视化(Excel, html以及jenkins集成)

    做性能测试通常在none GUI的命令行模式下运行Jmeter. 例如: jmeter -n -t /opt/las/JMeter/TestPlan/test.jmx -l /opt/las/JMet ...

  8. C语言:strcpy()和memcpy()

    一.strcpy和memcpy都是标准C库函数,它们有下面的特点:      1.strcpy提供了字符串的复制.即strcpy只用于字符串复制,并且它不仅复制字符串内容之外,还会复制字符串的结束符. ...

  9. 【Flash 插件】时钟类插件

    1.honehone_clock人体时钟实现 原理:就是在网页上播放已写好的.SWF文件. 效果如下: 效果一:背景透明,推荐为白色或浅背景 效果二:背景白色,推荐黑色或深色背景 实现步骤: 先引用 ...

  10. 破解无线网络密码-BT3如何使用3

    BT3 虚拟机 SNOOPWEP2 破解无线网络WEP密钥图解 1.下载BT3 光盘映像文件(ISO格式),比如:bt3-final.iso: 用WinISO 或 UltraISO(这个还支持DVD ...