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. HTML中添加<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    https://www.cnblogs.com/nxl0908/p/7245837.html Edge模式告诉IE以最高级 模式渲染文档,也就是任何IE版本都以当前版本所支持的最高级标准模式渲染,避免 ...

  2. 从咖啡馆的经营看 Web 应用的扩展

    我经营着一家咖啡馆.经营成本同所用的资源成正比. 我的咖啡馆店面大概有一百平方英尺(约九平方米),雇佣了一个咖啡师,一台咖啡机. 营业能力: 每次能够服务一个顾客,用三分钟泡制一杯咖啡,算下来服务一个 ...

  3. 开启session

    在index.php中开启 session_start();

  4. js_模块化

    https://www.cnblogs.com/scq000/p/10647128.html

  5. 对于Json的认识

    Json简介 1. JSON 是什么 JSON,全称是 JavaScript Object Notation,即 JavaScript 对象标记法.   JSON 是一种轻量级(Light-Weigh ...

  6. v8-su-root

    1.下载userdebug版本 2.设置模块打开develop options 3.勾选usb debugging 4.adb remount 5.解压SuperSU_N.7z(联系我索取)并push ...

  7. mysqli链接数据库示例代码

    $mysqli = new mysqli("localhost", "数据库用户名", "数据库密码", "数据库名称" ...

  8. ubuntu使用百度云盘插件

    Firefox 插件地址 https://addons.mozilla.org/zh-CN/firefox/addon/baidu-pan-exporter/ 安装后重启Firefox,然后百度云下载 ...

  9. java基础68 JavaScript城市联动框(网页知识)

    1.城市联动框 <!doctype html> <html> <head> <meta charset="utf-8"> <t ...

  10. OKR.2019

    转眼又一年过去了,回顾审视一年的得失,规划下一年的奋斗目标.Review And Planning,让全新的2019迎来全新的自己. O1 学习软件开发技术知识 KR1.1 阅读<CLR via ...