HDU - 1022 Train Problem I STL 压栈
Train Problem I
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 41471 Accepted Submission(s): 15510
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.



end of file. More details in the Sample Input.
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.
3 123 312
in
in
in
out
out
out
FINISH
No.
FINISH
通过火车进站前的顺序判断是否能改变为所给的顺序,火车需先进站然后再出站,可用STL中的stack实现,这里用数组模拟压栈
#include<stdio.h>
#include<string.h>
int main()
{
int n;
char s1[20]={0},s2[20]={0},s3[20];
int s1_in[20],s2_in[20];
while(~scanf("%d %s %s",&n,s1,s2))
{
memset(s3,0,sizeof(s3));//需对数组进行清空 int s[20]={0};
int i1=0,i2=0,i3=0,i=0;
//scanf("%s" "%s",s1,s2);
for(i1=0;i1<n;i1++)//将字符转换为数字
{
s1_in[20]=s1[i]-'0';
s2_in[20]=s2[i]-'0'; }
for(i1=0;i1<n;i1++)
{
s3[i3]=s1[i1];//火车进站
i3++;
i++;
while(s3[i3-1]==s2[i2]&&i2<n)
{
i3--;
s[i]=1;
i2++;
i++;
}
}
//printf("%d %d %d %d\n",i1,i2,i3,i);
if(i2==n)//火车全部出站
{
printf("Yes.\n");
for(i1=0;i1<i;i1++)
{
if(s[i1]==1)
{
printf("out\n");
}
else
printf("in\n");
}
printf("FINISH\n");
}
else
{
printf("No.\n");
printf("FINISH\n");
}
}
return 0;
}
HDU - 1022 Train Problem I STL 压栈的更多相关文章
- HDU 1022 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(栈的操作规则)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1022 Train Problem I Time Limit: 2000/1000 MS (Java/Ot ...
- hdu 1022 Train Problem I(栈的应用+STL)
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1022 Train Problem I[给出两个长n的串,入栈和出栈顺序,判断入栈顺序是否可以匹配出栈顺序]
Train Problem I 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 As the new term comes, the Ignatius Train Sta ...
- hdu 1022 Train Problem I【模拟出入栈】
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- Hdu 1022 Train Problem I 栈
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 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(数据结构,栈,递归,dfs)
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- HDU 1022 Train Problem I
A - Train Problem I Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
随机推荐
- HDU 2073 叠框
解题报告:一个字符串的题,最恶心的还是格式问题,PE了很多次,要求是每个测试数据的后面都带有一个空行,但是最后一个不能有空行,所以只能把第一组 数据的前面不输出空行,而后面的每一组数据都输出空行,这样 ...
- Oracle嵌套表
一.介绍 1.定义 嵌套表是表中之表.一个嵌套表是某些行的集合,它在主表中表示为其中的一列.对主表中的每一条记录,嵌套表可以包含多个行.在某种意义上,它是在一个表中存储一对多关系的一种方法. ...
- weblogic 反序列化补丁绕过漏洞的一个批量检测shell脚本(CVE-2017-3248 )
~ 以下内容,仅供学习参考 ~ weblogic 反序列化补丁绕过漏洞已经出了两个月了,balabala ~~~ 废话不说,拿到该漏洞的利用工具weblogic.jar,但只能一个个检测ip和端口,效 ...
- 倍增 Tarjan 求LCA
...
- ES6的优雅方法
1.箭头函数 // ES5 var selected = allJobs.filter(function (job) { return job.isSelected(); }); // ES6 var ...
- Groovy/Spock 测试导论
Groovy/Spock 测试导论 原文 http://java.dzone.com/articles/intro-so-groovyspock-testing 翻译 hxfirefox 测试对于软件 ...
- dropload的使用记录
这次做一个H5的页面,需要用到上拉加载,下拉刷新的功能,在网上看到ximen写的dropload.js可以满足需求(此处致谢作者),但是用的时候还是踩了一些坑,这里记录下来备忘. 一些小问题:1. m ...
- 洛谷 P4559: bzoj 5319: [JSOI2018]军训列队
题目传送门:洛谷 P4559. 题意简述: 有 \(n\) 个学生,编号为 \(i\) 的学生有一个位置 \(a_i\). 有 \(m\) 个询问,每次询问编号在 \([l,r]\) 区间内的学生跑到 ...
- 【FCS NOI2018】福建省冬摸鱼笔记 day4
第四天. 动态规划专题,讲师:闫神 讲了一些DP优化技巧,然而思想难度好大啊……根本没想到能优化那地步,连DP方程都没有呢. 不过有几题我还是想明白了. 讲了单调队列,决策单调性,四边形不等式,斜率优 ...
- Python time()方法
from:http://www.runoob.com/python/att-time-time.html 描述 Python time time() 返回当前时间的时间戳(1970纪元后经过的浮点秒数 ...