Train Problem I

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 51329    Accepted Submission(s): 19314

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

 
 题意:给出一个n,有两个序列,每个序列里有n个元素,问能不能利用栈把第一个序列变成第二个序列。 分析:栈的简单应用,注意每次都要把栈清空
 
#include<iostream>
#include<string.h>
#include<queue>
#include<stack>
using namespace std;
stack<char>a;
int main()
{
int n;
int vis[];
char s[],ss[];
while(cin>>n>>s>>ss&&n)
{
int j=,k=;
for(int i=;i<n;i++)
{
a.push(s[i]);
vis[k++]=;
while(!a.empty()&&a.top()==ss[j])
{
vis[k++]=;
a.pop();
j++;
}
}
if(a.empty())
{
cout<<"Yes."<<endl;
for(int i=;i<k;i++)
{
if(vis[i]==)
cout<<"in"<<endl;
else
cout<<"out"<<endl;
}
cout<<"FINISH"<<endl;
}
else
{
cout<<"No."<<endl;
cout<<"FINISH"<<endl;
}
while(!a.empty())
a.pop(); }
return ;
}
 

hdu-1022-栈的更多相关文章

  1. HDU 1022 Train Problem I

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

  2. HDU 1022 火车进站【栈】

     题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1022 题目大意: 题目大概意思:有N辆火车,以序列1方式进站,判断是否能以序列2方式出栈.进站不一定 ...

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

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

  4. Train Problem I hdu 1022(栈)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=1022 题意:给出火车的进站与出站顺序,判断是否可以按照给出的出站顺序出站. #include < ...

  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(栈模拟)

    传送门 Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of st ...

  7. 栈的简单应用 HDU 1022 http://acm.hdu.edu.cn/showproblem.php?pid=1022

    #include<stdio.h> #include<stack> #include<string.h> #define N 20 using namespace ...

  8. HDOJ/HDU 1022 Train Problem I(模拟栈)

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

  9. HDU Train Problem I 1022 栈模拟

    题目大意: 给你一个n 代表有n列 火车,  第一个给你的一个字符串 代表即将进入到轨道上火车的编号顺序, 第二个字符串代表的是 火车出来之后到顺序, 分析一下就知道这,这个问题就是栈, 先进后出吗, ...

  10. hdu 1022 Train Problem I(栈)

    #include<iostream> #include<vector> #include<cstring> #include<string> #incl ...

随机推荐

  1. EZOJ #201

    传送门 分析 这个题和寿司晚宴有点像 我们知道大于$\sqrt n$的质因子最高就是一次 于是我们对所有数以他的大质数为关键字排序 设dp[i][p2][p3][p5][p7][p11][p13][0 ...

  2. jQuery 演变史

    一.说明 最近我读完了 jQuery 官方的博客仓库,目的是为了梳理清楚 jQuery API 接口的演变过程.从而明确知道在对应版本下使用正确.合适的 API,以下便是我的总结笔记. jQuery ...

  3. javascript总结7:算术运算符

    1  运算符: 加号+ 如果是数字类型的变量相加,那么结果为数字类型; 如果是非数字类型的变量相加,结果为字符串类型 2  减号- 如果是非数字类型的变量相减结果为  NaN 3 乘号 * 如果是非数 ...

  4. Linux下的strerror是否线程安全?

    下列是glibc-2.14中的源代码: 点击(此处)折叠或打开 char * strerror (errnum) int errnum; { char *ret = __strerror_r (err ...

  5. 申请参加腾讯云自媒体分享计划,送代金券+CN域名

    文章介绍 看到腾讯支持博客了,就尝试下,看看效果如何. 文章属于转载,文末有文章来源,转载注明出处. 活动规则 活动资格:面向腾讯云官网已注册且完成实名认证用户,除协作者之外,其余用户均可参与; 如何 ...

  6. Java主线程如何等待子线程执行结束(转)

    工作中往往会遇到异步去执行某段逻辑, 然后先处理其他事情, 处理完后再把那段逻辑的处理结果进行汇总的产景, 这时候就需要使用线程了. 一个线程启动之后, 是异步的去执行需要执行的内容的, 不会影响主线 ...

  7. java 七牛上传图片到服务器(采用的html5 压缩 传输base64方式)

    //html 页面如下<div class="form-group"> <label class="col-sm-2 control-label&quo ...

  8. [转]sessionStorage()和localStorage()的用法

    JS的本地保存localStorage.sessionStorage用法总结: 1. localStorage.sessionStorage是Html5的特性,IE7以下浏览器不支持 为什么要掌握lo ...

  9. 「Luogu 1471」 方差

    题目背景 滚粗了的HansBug在收拾旧数学书,然而他发现了什么奇妙的东西. 题目描述 蒟蒻HansBug在一本数学书里面发现了一个神奇的数列,包含N个实数.他想算算这个数列的平均数和方差. 输入输出 ...

  10. 《C#多线程编程实战》2.8 Barrier

    不得不说,C#的同步线程的机制是真的多. 各式各样.几乎各种场景下都有可以使用的同步机制. 今天说的,就是比较有意思了. 等待的机制很简单,单纯的等待. 使用的方法我就等. 等待的东西或者内容则是你自 ...