HDU Train Problem I (STL_栈)
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 railway). Print a line contains "FINISH" after each test case. More details in the Sample Output.
3 123 321
3 123 312
Yes.
in
in
in
out
out
out
FINISH
No.
FINISHFor the first Sample Input, we let train 1 get in, then train 2 and train 3.HintHint
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.".
栈的简单应用,本题具体解答在白书上有.
以下附上代码:用c++交会错。用G++就不会。。
。求解释
#include<iostream>
#include<stack>
#include<cstring>
#include<cstdio>
using namespace std;
int a[10000],ans[20000],b[10000];
stack<int>ss;
int main()
{
int n,i,j,k;
string s1,s2;
while(scanf("%d",&n)!=EOF){
cin>>s1>>s2;
for(i=1;i<=n;i++) a[i]=s1[i-1]-'0';
for(j=1;j<=n;j++) b[j]=s2[j-1]-'0';
while(!ss.empty()) ss.pop();
k=0,j=1;
for(i=1;i<=n;i++) {
ss.push(a[i]);
ans[++k]=1;
while(!ss.empty() && ss.top()==b[j]) {
ss.pop();
ans[++k]=2;
j++;
}
}
if(k==2*n) {
printf("Yes.\n");
for(i=1;i<=2*n;i++) {
if(ans[i]==1) printf("in\n");
else printf("out\n");
}
}
else printf("No.\n");
printf("FINISH\n");
}
return 0;
}
HDU Train Problem I (STL_栈)的更多相关文章
- HDU Train Problem I 1022 栈模拟
题目大意: 给你一个n 代表有n列 火车, 第一个给你的一个字符串 代表即将进入到轨道上火车的编号顺序, 第二个字符串代表的是 火车出来之后到顺序, 分析一下就知道这,这个问题就是栈, 先进后出吗, ...
- HDU 1022 Train Problem I(栈的操作规则)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1022 Train Problem I Time Limit: 2000/1000 MS (Java/Ot ...
- HDU 1022.Train Problem I【栈的应用】【8月19】
Train Problem I Problem Description As the new term comes, the Ignatius Train Station is very busy n ...
- hdu 1022 Train Problem I(栈的应用+STL)
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- Train Problem I--hdu1022(栈)
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- HDU 1022 Train Problem I(栈模拟)
传送门 Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of st ...
- HDOJ/HDU 1022 Train Problem I(模拟栈)
Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot o ...
- hdu Train Problem I(栈的简单应用)
Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot o ...
- hdu 1022 Train Problem I(栈)
#include<iostream> #include<vector> #include<cstring> #include<string> #incl ...
随机推荐
- MQTT---HiveMQ源代码具体解释(八)Netty-WebSocket
源博客地址:http://blog.csdn.net/pipinet123 MQTT交流群:221405150 基于netty实现Webscoket相对来说就是相当简单,所以本讲中就不搞太复杂的了,给 ...
- 剑指Offer读书笔记(持续更新中)
(1)定义一个空的类型,里面没有不论什么成员变量和成员函数,对该类型求sizeof,得到的结果是多少? 答案是1.空类型的实例中不包括不论什么信息,本来求sizeof应该是0,可是当我们声明该类型实例 ...
- WebGL 权威资源站小聚
WebGL 权威资源站小聚 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用协议 转载请保留此句 ...
- 去哪网实习总结:JavaWeb中文传參乱码问题的解决(JavaWeb)
本来是以做数据挖掘的目的进去哪网的.结构却成了系统开发... 只是还是比較认真的做了三个月.老师非常认同我的工作态度和成果... 实习立即就要结束了,总结一下几点之前没有注意过的变成习惯和问题,分享给 ...
- Oracle数据库三种标准的备份方法
Oracle数据库的三种标准的备份方法: 1.导出/导入(EXP/IMP). 2.热备份. 3.冷备份. 注释:导出备件是一种逻辑备份,冷备份和热备份是物理备份. 一.导出/导入(Export/Imp ...
- angular4父组件向子组件传值,子组件向父组件传值的方法
父组件向子组件传值 @Input 文件目录 父组件: father.template.html <h1>父组件</h1> <cmt-child [data]='dat ...
- java生成6位随机数的5种方法
转自:https://blog.csdn.net/u012491783/article/details/76862526/
- Centos6.5添加Epel和Remi源安装Lamp环境
想搭建一个Lamp环境,因为编译安装太麻烦,对于我这样的新手来说,太过于复杂.而CentOS自带的Apache.MySql和PHP的版本都太低,不想用.上百度搜了一轮,原来可以通过添加Epel和Rem ...
- POJ 2239 匈牙利算法
思路:最大匹配 也是很裸的一道题-. // by SiriusRen #include <cstdio> #include <cstring> #include <alg ...
- c++ set_union set_intersection使用
自定义类型也可以构造set,但同样必须定义“小于”运算符,set中的元素从小到大排列好了 #include<iostream>#include<string>#include ...