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. Objective-C:协议protocol

    六.协议(protocol) 关键字:@optional.@required (1)是一个类共享的一个方法列表 (2)它声明了一系列的方法而不进行实现 (3)遵从某个协议,就是需要实现协议中的方法 ( ...

  2. 稀疏数据压缩查询方法:Rank & Select 操作

    1.稀疏数据的例子 对于网络图对应的节点关联矩阵.数据生成的哈希表等,这些存储起来是稀疏的,这样我们就会想到需要压缩空间.但是在压缩存储空间的同时,还要支持高效的查询操作. Rank & Se ...

  3. go语言基础之append函数的使用

    1.append函数的使用 作用:在原切片的末尾添加元素 示例: package main //必须有个main包 import "fmt" func main() { s1 := ...

  4. 80端口占用异常解决方法java.net.BindException: Address already in use: JVM_Bind:80(或8080)

    1:Tomcat(或其他Web容器)启动时控制台报错如下示: 2007-8-2 15:20:43 org.apache.coyote.http11.Http11Protocol init 严重: Er ...

  5. LRU Cache leetcode java

    题目: Design and implement a data structure for Least Recently Used (LRU) cache. It should support the ...

  6. 为什么不取消注册BroadcastReceiver会导致内存泄漏

    原始问题是这样 然后扔到了很多Android开发交流群里. 接着产生了很多的见解,我感觉比较靠谱的有以下: 网友对我问题的回答 1.onDestroy被回调代不代表Activity被回收了? 官方是这 ...

  7. C#创建数字证书并导出为pfx,并使用pfx进行非对称加解密

    本文源程序下载:http://download.csdn.net/source/2444494 我的项目当中,考虑到安全性,需要为每个客户端分发一个数字证书,同时使用数字证书中的公私钥来进行数据的加解 ...

  8. (转)[原创]在ios android设备上使用 Protobuf (使用源码方式)

    自:http://game.ceeger.com/forum/read.php?tid=13479 如果你的工程只能以.Net 2.0而不能以.Net 2.0 subset运行,请看另外一个方法. 地 ...

  9. 怎样增加Dave 英语学习小组

    一.     增加小组 英语对IT 是非常重要的,但非常多人都不能坚持去学习,Dave 英语学习小组成立与已经超过半年,如今进行扩招.欢迎想提高英语,而且能够坚持每天学习的人,增加Dave 的小组.并 ...

  10. Python网络编程 - 请求地址上的文件并下载

    我们用到了requests库,由于是第三方的,必须下载 如果是python 2.x用下面命令 pip install requests python 3.x用下面命令 easy_install req ...