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


Problem Description
As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is the fastest all over the world ^v^). But here
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.
 

Input
The input contains several test cases. Each test case consists of an integer, the number of trains, and two strings, the order of the trains come in:O1, and the order of the trains leave:O2. The input is terminated by the
end of file. More details in the Sample Input.
 

Output
The output contains a string "No." if you can't exchange O2 to O1, or you should output a line contains "Yes.", and then output your way in exchanging the order(you should output "in" for a train getting into the railway,
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.
 

Sample Input

3 123 321
3 123 312
 

Sample Output

Yes.
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 压栈的更多相关文章

  1. HDU 1022 Train Problem I (数据结构 —— 栈)

    Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot o ...

  2. HDU 1022 Train Problem I(栈的操作规则)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1022 Train Problem I Time Limit: 2000/1000 MS (Java/Ot ...

  3. hdu 1022 Train Problem I(栈的应用+STL)

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. HDU 1022 Train Problem I[给出两个长n的串,入栈和出栈顺序,判断入栈顺序是否可以匹配出栈顺序]

    Train Problem I 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述 As the new term comes, the Ignatius Train Sta ...

  5. hdu 1022 Train Problem I【模拟出入栈】

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  6. Hdu 1022 Train Problem I 栈

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  7. 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 ...

  8. hdu 1022:Train Problem I(数据结构,栈,递归,dfs)

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  9. HDU 1022 Train Problem I

    A - Train Problem I Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

随机推荐

  1. ConcurrentHashMap 产生NullPointerException

    今天测试在发给我一段报错日志后,根据日志定位到从ConcurrentHashMap 的缓存中get的时候,ConcurrentHashMap的底层抛出了空指针,当时感觉很奇怪为什么在get的时候产生空 ...

  2. TED_Topic4:How I fell in love with quasars, blazars and our incredible universe

    By Jedidah Isler # Background about our speaker Jedidah Isler studies blazars(耀变天体) — supermassive h ...

  3. 关于onConfigurationChanged

    这两天测试app时,发现一个奇怪问题,app在启动后,Activity会onCreate两次,起初以为是横屏设置导致,随即在Activity中添加了android:configChanges=&quo ...

  4. python——脚本和print

    脚本和print 1.脚本文件 <Python 基础教程>(第二版)中 P118页,原操作为下: 1 _metaclass_ = type 2 3 class Person: 4 def ...

  5. Shell-help格式详解

    前言 linux shell命令通常可以通过-h或--help来打印帮助说明,或者通过man命令来查看帮助,有时候我们也会给自己的程序写简单的帮助说明,其实帮助说明格式是有规律可循的 帮助示例 下面是 ...

  6. Python Challenge 第 2 关攻略:ocr

    text="那一大推乱码" 方案1 from collections import Counter print(Counter(text)) 方案2 import string & ...

  7. js点击页面其他地方如何隐藏div元素菜单

    web页面常用的一个需求,写下拉菜单是我们往往不是用select_option,而是自定义一个元素列出选项来满足需求,当我们点击按钮出现菜单, 点击按钮或菜单以外页面空白地方隐藏该菜单,这里提供一种简 ...

  8. ArcMap2SLD添加中文支持

    首先,你可以从作者提供的链接下载ArcMap2SLD.zip(支持ArcMap10.2) 1.打开LUT_sld_mapping_file.xml文件(上传文件中已经修改)修改文件<LUT> ...

  9. Python 常用的内建函数

    内建函数 ​ Build-in Function,启动python解释器,输入dir(__builtins__), 可以看到很多python解释器启动后默认加载的属性和函数,这些函数称之为内建函数, ...

  10. [java笔记]常用的设计模式

    1.单例设计模式 单例设计模式:保证一个类仅有一个实例,并提供一个访问它的全局访问点. 1)构造方法私有化 2)声明一个本类对象 3)给外部提供一个静态方法获取对象实例 例如: class Singl ...