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 ...
随机推荐
- POJ 2133
类似于DP一样做,但这题有个大坑,自己看DIS吧.... #include <iostream> #include <cstdio> #include <cstring& ...
- Java笔试面试题001
Java笔试面试题之中的一个 1.Struts1中actionform和action属于MVC哪一层,为什么? 解答:actionform和action属于MVC的Model层,Action用来处理业 ...
- 视差滚动demo (pc)
根据设计图设定每屏的高度,js会自动缩放到全屏尺寸,效果要大尺寸才能看的出来 demo :http://runjs.cn/detail/uvizsekd <!DOCTYPE html> & ...
- 英语发音规则---G字母
英语发音规则---G字母 一.总结 一句话总结: 1.G发[g]音? bag [bæg] n. 袋:猎获物 go [gəʊ] vi. 走:达到 garden ['gɑːd(ə)n] n. 花园 gla ...
- Oracle的awr和ash
1. 10g之前 用户的连接将产生会话,当前会话记录保存在v$session中:处于等待状态的会话会被复制一份放在v$session_wait中.当该连接断开后,其原来的连接信息在v$sess ...
- 双系统下Ubuntu安装教程
一.下载Ubuntu镜像包 二.用老毛桃制作U盘启动盘 三.下载Universal USB Installer 下载后无需安装,直接运行Universal USB Installer, step1: ...
- vue 父子组件通信props/emit
props 1.父组件传递数据给子组件 父组件: <parent> <child :childMsg="msg"></child>//这里必须要 ...
- tomcat 和 jboss的热部署(热发布)问题
所谓的热部署(热发布)(下面称为“热部署”),就是说,在web工程发布之后,不可避免的,会遇到修改BUG的问题.现在的热部署就是为了解决这个问题,其功能就是说:在不停止web服务的同时,对jsp和Ja ...
- 转:Hibernate中Criteria和DetachedCriteria的完整用法
原文地址:http://blog.sina.com.cn/s/blog_667528fd0100rkrf.html 设计上可以灵活的根据 Criteria 的特点来方便地进行查询条件的组装.现在对 H ...
- Ubuntu18.04解决鼠标移动到Gnome顶栏左上角窗口不能平铺( Activites Overview 界面),和应用程序扩展不好用问题。
在用习惯了GNOME我们知道一个很好的功能就是通过鼠标移动到Gnome顶栏左上角后所有打开的窗口就会平铺在显示器上方便我们选不同的窗口(Activites Overview 界面),苹果MAC系统也有 ...