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 ...
随机推荐
- 20155225 2016-2017-2 《Java程序设计》第七周学习总结
20155225 2016-2017-2 <Java程序设计>第七周学习总结 教材学习内容总结 java提供的时间处理API 认识时间与日期,时间日期处理不是我想象中那么简单的问题,涉及地 ...
- Element-UI 表格 列过多内容换行问题
本文地址:http://www.cnblogs.com/veinyin/p/8487098.html 一般表格不会有很多列,所以在使用时会很方便,但是如果有25+个列时,就会发现宽度完全不够用,只有 ...
- 【leetcode 简单】 第七十八题 Nim游戏
你和你的朋友,两个人一起玩 Nim游戏:桌子上有一堆石头,每次你们轮流拿掉 1 - 3 块石头. 拿掉最后一块石头的人就是获胜者.你作为先手. 你们是聪明人,每一步都是最优解. 编写一个函数,来判断你 ...
- Xor Sum(HDU4825 + 字典树)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4825 题目: 题意: 先给你n个数,再进行q次查询,每次查询数s与原来给的n个数异或和最大的数. 思 ...
- SQL Server 问题之 排序规则(collation)冲突
一.写在前面 最近公司进行开发环境升级,数据库也准备了一个新的服务器,一切准备好后开始数据迁移,采取的方式为对现有Database(现有服务器Windows Server 2003 + SQL Ser ...
- oracle建表,设置主键,修改属性等
--建表 create table book( book_id number(10), book_name varchar2(20), book_price number(10,2), book_au ...
- 生成Word/ATU报表提示 font family not found
1.先从你本机 C:\Windows\Fonts 拷贝或者网络上下载你想要安装的字体文件(*.ttf文件)到 /usr/share/fonts/chinese/TrueType 目录下(如果系统中没有 ...
- qt使用动态库(DLL)
本文主要讲解在QT开发环境中如何使用VC生成的DLL及QT自身生成的DLL.至于其它情况本文不作讨论. 连接库分为2种 (1)动态连接库,通常有.h .lib .dll三个文件,功能实现在dll中 ( ...
- Spring Boot连接Mysql数据库问题解决
在spring Boot项目中使用mysql数据库进行数据库的增删查改,出现以下错误: Error starting ApplicationContext. To display the auto-c ...
- 在VS中让一个JS文件智能提示另一个JS文件中的成员2--具体引用
我们知道,在html中,利用<script language="javascript" type="text/javascript" src=" ...