(stack)Train Problem I hdu1022
Train Problem I
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 42031 Accepted Submission(s): 15731
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.".
PS:emmmm,这个我不知怎么说,先贴代码吧
#include<iostream>
#include <stack>
#include <cstring>
using namespace std;
int main()
{
stack<char>s1;
stack<char>s2;
int n,i,j,a[];
char str1[],str2[];
while(cin>>n)
{
memset(str1,,sizeof(str1));
memset(str2,,sizeof(str2));
cin>>str1;
cin>>str2;
for(i=strlen(str2)-;i>=;i--)
s2.push(str2[i]); //入栈
for(i=,j=;i<strlen(str1);i++)
{
s1.push(str1[i]); //入栈
a[j++]=;
while(!s1.empty()&&s1.top()==s2.top())
{
s1.pop();
s2.pop();
a[j++]=;
}
}
if(s1.empty()&&s2.empty())
{
cout<<"Yes."<<endl;
for(i=;i<*n;i++)
{
if(a[i]==)
cout<<"in"<<endl;
else
cout<<"out"<<endl;
}
}
else
{
cout<<"No."<<endl;
while(!s1.empty())
s1.pop();
while(!s2.empty())
s2.pop();
}
cout<<"FINISH"<<endl;
}
return ;
}
(stack)Train Problem I hdu1022的更多相关文章
- Java的堆(Heap)和栈(Stack)的区别
Java中的堆(Heap)是一个运行时数据区,用来存放类的对象:栈(Stack)主要存放基本的数据类型(int.char.double等8种基本数据类型)和对象句柄. 例1 int a=5; int ...
- [置顶] ※数据结构※→☆线性表结构(stack)☆============栈 序列表结构(stack sequence)(六)
栈(stack)在计算机科学中是限定仅在表尾进行插入或删除操作的线性表.栈是一种数据结构,它按照后进先出的原则存储数据,先进入的数据被压入栈底,最后的数据在栈顶,需要读数据的时候从栈顶开始弹出数据.栈 ...
- PHP实现栈(Stack)数据结构
栈(Stack),是一种特殊的后进先出线性表,其只能在一端进行插入(插入一般称为压栈.进栈或入栈)和删除(删除一般称为弹栈.退栈或出栈)操作,允许进行插入和删除操作的一端称为栈顶,另一端则称为栈底.栈 ...
- C# 堆栈(Stack)和队列(Queue)
一.什么是堆?(Heap) 堆是无序的,是一片不连续的内存域,由用户自己来控制和释放,如果用户自己不释放的话,当内存达到一定的特定值时,通过垃圾回收器(GC)来回收. 是程序运行期 ...
- 对Android中的堆栈的理解(Stack)
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/Ln_ZooFa/article/details/50337529 堆栈空间分配 栈(操作系统): ...
- 堆(heap)、栈(stack)、方法区(method)
JVM内存分为3个区:堆(heap).栈(stack).方法区(method) 1.堆(heap):存储的全部对象,每个对象有个与之对应的class信息.即通过new关键字和构造器创建的对象.JVM只 ...
- C# 队列(Queue)和 堆栈(Stack)
C# 队列(Queue)和 堆栈(Stack) C# 队列(Queue) 队列(Queue)代表了一个先进先出的对象集合.当您需要对各项进行先进先出的访问时,则使用队列.当您在列表中添加一项,称为入队 ...
- C# 编程中的堆栈(Stack)和队列(Queue)
一.什么是堆?(Heap) 堆是无序的,是一片不连续的内存域,由用户自己来控制和释放,如果用户自己不释放的话,当内存达到一定的特定值时,通过垃圾回收器(GC)来回收. 是程序运行期 ...
- 我理解的数据结构(二)—— 栈(Stack)
我理解的数据结构(二)-- 栈(Stack) 一.栈基础 栈是一种线性结构 相比较数组,栈对应的操作是数组的子集 只能从一端添加元素,也只能从同一端取出元素,这一端称为栈顶 栈是一种后进先出的数据结构 ...
随机推荐
- Python_复习_习题_29
# 之前做得的题 以后再遇到能保证会# 下周二考 :所有的知识# 面试题:认真对待## 三元运算符# 接收结果的变量 = 条件为真的结果 if 条件 else 条件为假的结果# 接收结果的变量 = “ ...
- 修改sga_max_size大小后重启数据库报 ORA-00851
http://blog.itpub.net/30150152/viewspace-1449898/
- 个人阅读作业Week5
一.总结体会 团队项目已经进行了很多周,我们团队从刚开始的基础薄弱到现在的大家都可以运用Android来编写程序,共同完成一个app的开发使用. 刚开始做团队项目之时,我们团队就开了一个会,确定了以后 ...
- 【转】STM32和ARM的区别
转自:http://www.cnblogs.com/nuc-boy/archive/2012/09/11/2680157.html 这个问题大概2009年的时候很多人就在问,请看09年的时候大家给出的 ...
- [日常工作]Win2008r2 以及更高版本的操作系统安装Oracle10.2.0.5
1. 当时有特殊需求, 客户有win2008r2sp1以上的windows系统,但是数据库要使用Oracle10.2.0.5 的版本. 问题: 1. Oracle10 最高支持到 Win2008sp2 ...
- PRML读书笔记_绪论曲线拟合部分
一.最小化误差函数拟合 正则化( regularization )技术涉及到给误差函数增加一个惩罚项,使得系数不会达到很大的值.这种惩罚项最简单的形式采用所有系数的平方和的形式.这推导出了误差函数的修 ...
- number (2)编译错 (类的大小写错误) Filewriter cannot be resolved to a type
没找到所使用的类所在的类定义,一般常见于使用了外部jar中的类,但有对应的import语句.比如,如果程序中使用了ArrayList这个类,但你程序类文件的最开始import部分如果没有import ...
- webstrom 安装Babel
https://www.jianshu.com/p/b9bd2ec9ec80 https://www.cnblogs.com/zhishaofei/p/6061568.html https://blo ...
- BZOJ3530[Sdoi2014]数数——AC自动机+数位DP
题目描述 我们称一个正整数N是幸运数,当且仅当它的十进制表示中不包含数字串集合S中任意一个元素作为其子串.例如当S=(22,333,0233)时,233是幸运数,2333.20233.3223不是幸运 ...
- BZOJ3160 万径人踪灭(FFT+manacher)
容易想到先统计回文串数量,这样就去掉了不连续的限制,变为统计回文序列数量. 显然以某个位置为对称轴的回文序列数量就是2其两边(包括自身)对称相等的位置数量-1.对称有啥性质?位置和相等.这不就是卷积嘛 ...