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. LINUX 查看CUP温度

    在Linux下可以通过lm_sensors来查看CPU的温度(当然你的硬件首先要支持),要使用这个功能要有内核相关模块(比如I2C)的支持,下面说一下操作方法: 先看一下你的机器上是否安装了lm_se ...

  2. Android不间断上报位置信息-应用进程防杀指南

    没用的 除非加入白名单 或者用户自己设置锁屏后不被杀死 不然的话 锁屏5分钟以内app会被杀死,包 括所有的service. 说白了就是定位不要纯依赖gps,很多硬件为了省电,会对熄屏下的模块功能和运 ...

  3. JavaScript判断是否是数组

    在 ECMAScript5中定义了一个新的方法Array.isArray(). 如果参数是数组的话,就返回true eg: Array.isArray([]); // true 如果里面换一个类似数组 ...

  4. jQuery提供的存储接口

    jQuery.data( element, key, value ) //静态接口,存数据jQuery.data( element, key ) //静态接口,取数据 .data( key, valu ...

  5. Appium移动端自动化测试之元素定位(三)

    1.name定位 driver.find_element_by_id(') driver.find_element_by_id(') driver.find_element_by_name('登录') ...

  6. Struts2获取Action中的数据

    当我们用Struts2框架开发时,经常有要获取jsp页面的数据或者在jsp中获取后台传过来的数据(Action),那么怎么去获取自己想要的数据呢? 后台获取前端数据: 在java程序中生成要获取字段的 ...

  7. (转)MongoDB入门分享-笔记整理精选

    原文地址:http://www.cnblogs.com/Kummy/p/3372729.html 最近在学习MongoDB,怕以后忘记,自己做了一个整理,给不知道的小伙伴一起分享学习一下. 第一步&g ...

  8. jQuery插件编写学习+实例——无限滚动

    最近自己在搞一个网站,需要用到无限滚动分页,想想工作两年有余了,竟然都没有写过插件,实在惭愧,于是简单学习了下jQuery的插件编写,然后分享出来. 先说下基础知识,基本上分为两种,一种是对象级别的插 ...

  9. asp.net 中input radio checked 无效

    把Jq代码中的$(...).attr("checked",true) 换成$(...).prop("checked",true) ,

  10. docker 镜像创建

    dockerfile FROM microsoft/aspnetcore:2.0 ARG source WORKDIR /app EXPOSE COPY ${source:-/} . ENTRYPOI ...