题目:
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

Hint

Hint

For the first Sample Input, we let train 1 get in, then train 2 and train 3.
So now train 3 is at the top of the railway, so train 3 can leave first, then train 2 and train 1.
In the second Sample input, we should let train 3 leave first, so we have to let train 1 get in, then train 2 and train 3.
Now we can let train 3 leave.
But after that we can't let train 1 leave before train 2, because train 2 is at the top of the railway at the moment.
So we output "No.".

 

思路:紫书上原题,题意是给你一个进站前的数列,判断这几个数能否通过类似入栈出栈的操作后得到题目所给的数列;

  用栈来模拟就好。

  ps:一定要注意输出格式!!!写完代码之后,愣是一直wa,开始是因为栈没清空,后又发现是输出格式不对!!!

    血的教训,改了好半天!!!

 #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <string> #define PI acos((double)-1)
#define E exp(double(1))
#define N 1000000
using namespace std; int main (void)
{
int t,a,b,flag,c;
string s,e,code;
stack<int>sk;
while(scanf("%d",&t) == && t)
{
cin>>s>>e;
flag=;
a=b=c=;
while(b<t)
{
if(s[a] == e[b])
{
a++;b++;
code[c++]=;
code[c++]=;
}
else if(!sk.empty() && e[b] == sk.top())
{
sk.pop();b++;
code[c++]=;
}
else if(a < t)
{
sk.push(s[a++]);
code[c++]=;
}
else
{
flag = ;
break;
}
}
if(flag)
{
cout<<"Yes."<<endl;
for(int i = ;i< *t;i++)
if(code[i])
cout<<"in"<<endl;
else
cout<<"out"<<endl;
}
else
cout<<"No."<<endl;
cout<<"FINISH"<<endl;
while(!sk.empty())
sk.pop();
}
return ;
}

杭电1022Train Problem I的更多相关文章

  1. 杭电1023Train Problem II

    地址:http://acm.hdu.edu.cn/showproblem.php?pid=1023 题目: Train Problem II Time Limit: 2000/1000 MS (Jav ...

  2. 杭电ACM(1002) -- A + B Problem II 大数相加 -提交通过

    杭电ACM(1002)大数相加 A + B Problem II Problem DescriptionI have a very simple problem for you. Given two ...

  3. 杭电ACM刷题(1):1002,A + B Problem II 标签: acmc语言 2017-05-07 15:35 139人阅读 评

    最近忙于考试复习,没有多少可供自己安排的时间,所以我利用复习之余的空闲时间去刷刷杭电acm的题目,也当对自己编程能力的锻炼吧. Problem Description I have a very si ...

  4. acm入门 杭电1001题 有关溢出的考虑

    最近在尝试做acm试题,刚刚是1001题就把我困住了,这是题目: Problem Description In this problem, your task is to calculate SUM( ...

  5. 杭电OJ——1198 Farm Irrigation (并查集)

    畅通工程 Problem Description 某省调查城镇交通状况,得到现有城镇道路统计表,表中列出了每条道路直接连通的城镇.省政府"畅通工程"的目标是使全省任何两个城镇间都可 ...

  6. 杭电ACM分类

    杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze ...

  7. HDU-2500 做一个正气的杭电人

    http://acm.hdu.edu.cn/showproblem.php?pid=2500 做一个正气的杭电人 Time Limit: 1000/1000 MS (Java/Others)    M ...

  8. 杭电 2047 阿牛的EOF牛肉串 (递推)

    阿牛的EOF牛肉串 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...

  9. 做一个正气的杭电人--hdu2500

    做一个正气的杭电人 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

随机推荐

  1. 宝宝书 & 网站

    1. 网站 妈妈帮 宝宝树 2. 图书推荐 育儿百科 育儿经 中国儿童智力方程 聪明宝宝营养食谱1001例

  2. [Django] 问题记录追踪表

    关注的网站: https://simpleisbetterthancomplex.com/ Linux部署 1. Ubuntu下vsftpd安装部署 2. Utuntu下Django+Apache+W ...

  3. 文件I/O:文件流→序列化

    ★文件流 文件操作是最简单最直接也是最容易想到的一种方式,我们说的文件操作不仅仅是通过FileInputStream/FileOutputStream这么“裸”的方式直接把数据写入到本地文件(像我以前 ...

  4. 【JavaEE】SSH+Spring Security整合及example

    到前文为止,SSH的基本框架都已经搭建出来了,现在,在这基础上再加上权限控制,也就是Spring Security框架,和前文的顺序一样,先看看需要加哪些库. 1. pom.xml Spring Se ...

  5. 蓝桥杯 第三届C/C++预赛真题(9) 夺冠概率(手工计算概率)

    足球比赛具有一定程度的偶然性,弱队也有战胜强队的可能. 假设有甲.乙.丙.丁四个球队.根据他们过去比赛的成绩,得出每个队与另一个队对阵时取胜的概率表: 甲 乙 丙 丁 甲 - 0.1 0.3 0.5乙 ...

  6. IOS开发之——企业版IDP的申请及“In House”发布

    本文转载至 http://blog.csdn.net/pjk1129/article/details/7572183 企业版IDP的申请及“In House”发布 原贴地址:http://blog.c ...

  7. 网络虚拟化之FlowVisor:网络虚拟层(下)

    在前面两篇文章:网络虚拟化之FlowVisor:网络虚拟层(上)和网络虚拟化之FlowVisor:网络虚拟层(中)中分别介绍了FLowVisor的特性和实现,三连载的最后一篇介绍虚拟网络的隔离机制. ...

  8. ZOJ 3490 String Successor(模拟)

    Time Limit: 2 Seconds Memory Limit: 65536 KB The successor to a string can be calculated by applying ...

  9. apk获取源码(dex2jar、jd-gui)

    1.下载dex2jar.zip,并解压文件 2.下载jd-gui.zip,解压文件 3.解压apk文件,找到其中的classes.dex 4.将classes.dex复制到dex2jar.bat所在目 ...

  10. wget -d --header

    wget -d --header="Host:www.sina.com" http://202.108.33.84 domain differ ip 防止Wget递归下载 假设Ng ...