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 ...
随机推荐
- angular4 get,post请求(带参数,与不带参数)
一:在app.module.ts引入HttpMoudle import { BrowserModule } from '@angular/platform-browser'; import { Htt ...
- 20155232 2016-2017-3 《Java程序设计》第7周学习总结
20155232 2016-2017-3 <Java程序设计>第7周学习总结 教材学习内容总结 第十三章 1.Greenwich MeanTime,格林威治时间,简称GMT时间,由观察太阳 ...
- CF 1008C Reorder the Array
You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it ...
- seq与Shell序列生成
有时候可能有这样的需要:用Shell生成类似0001这样的序列作为批次号,这里整理了一下个人的方法 方法一:通过seq命令 seq命令可以生成从某个数字到递增到另一数字的序列.用法如下: # seq ...
- MySQL Sakila样本数据库
Sakila样本数据库介绍 Sakila样本数据库是MySQL官方提供的一个模拟DVD租赁信息管理的数据库,提供了一个标准模式,可作为书中例子,教程.文章.样品,等等,对学习测试来说是个不错的选择. ...
- mysql修改表操作
一: 修改表信息 1.修改表名 alter table test_a rename to sys_app; 2.修改表注释 alter table sys_application comment '系 ...
- Entity Framework(EF的Model First方法)
EntityFramework,是Microsoft的一款ORM(Object-Relation-Mapping)框架.同其它ORM(如,NHibernate,Hibernate)一样, 一是为了使开 ...
- 阿里云CentOS下安装jdk
首先需要下载jdk: 由于oracle上的下载页面有跳转,直接用wget下载下来的只是html页面.可以用下面的命令: wget --no-cookies --no-check-certificate ...
- APScheduler API -- apscheduler.schedulers.base
apscheduler.schedulers.base API class apscheduler.schedulers.base.BaseScheduler(gconfig={}, **option ...
- Chrome 清除某个特定网站下的缓存
打开开发者工具(F12),选择 Network--Disable cache 即可.需要清除某网站缓存时 F12 打开开发者工具就会自动清除这个网站的缓存,而不必清除所有网站的缓存了.