传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1022

Train Problem I

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

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

 
Author
Ignatius.L
 
Recommend
We have carefully selected several similar problems for you:  1026 1023 1020 1032 1001 
 
分析:
此题不真正的仔细读难理解出事栈的应用,容易想成反序相等就yes的问题,此题题意是说输入的两列字符串,第一列表示进入的顺序,第二列表示出去的顺序,问你是否符合后进先出。

举出一列数据 7 1234567 4321576
上面数据应该是 in in in in out out out out in out in in out out;

所以不是反序才行 可以进到一半就出的

 
stl就是好用啊!
 
code:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
int n,i,j;
string str1,str2;
while(cin>>n>>str1>>str2)
{
stack<char> s;
vector<string> v;
for( i=,j=;i<n&&j<n;i++)
{
s.push(str1[i]);//元素进栈
v.push_back("in");//字符压进容器
while(s.top()==str2[j])//匹配
{
if(!s.empty())
{
s.pop();
v.push_back("out");
}
j++;
if(s.empty())
break;
}
}
if(j==n)//判断依据
{
printf("Yes.\n");
for(i=;i<v.size();i++)
cout<<v[i]<<endl;
cout<<"FINISH"<<endl;
}else
{
cout<<"No."<<endl<<"FINISH"<<endl;
}
}
return ;
}

HDU 1022 Train Problem I(栈的操作规则)的更多相关文章

  1. Hdu 1022 Train Problem I 栈

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

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

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

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

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

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

  5. HDU - 1022 Train Problem I STL 压栈

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

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

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

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

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

  8. HDU 1022 Train Problem I 模拟栈题解

    火车进站,模拟一个栈的操作,额外的栈操作,查看能否依照规定顺序出栈. 数据量非常少,故此题目非常easyAC. 直接使用数组模拟就好. #include <stdio.h> const i ...

  9. HDU 1022 Train Problem I

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

随机推荐

  1. Spring学习笔记:Spring整合Mybatis学习PPT(三:整合思路)

    三.Spring-Mybatis的整合思路

  2. Java线程入门第三篇

    Java内存模型(jmm) Why:保证多线程正确协同工作 看图说明: 文字解释:线程a和线程b通信过程,首先线程a把本地内存的共享变量更新到主内存中,然后线程b去读取主内存的共享变量,最后更新到自己 ...

  3. Linux服务器安装tomcat、JDK、SVN等常用开发软件总结

    本来本文发布到首页的,该网站运营人员移除了,说我这篇博文太简单了,如果感觉我这篇博文有用的,大家给个推荐,打一下运营人员的脸 目录 一.Ubuntu 16.04下安装JDK(spring 3.2不支持 ...

  4. PowerDesigner设置所有int主键自增脚本

    '*****************************************************************************dim model 'current mod ...

  5. 新手必需用!大道至简的前端编辑器Sublime Text

    很多人在进入学习前端的时候(包括我自己),除了选择学习合适的技术,还需要一个得(自)心(己)应(喜)手(欢)的开发工具,一个得心应手的开发工具除了可以令你的效率大大提高,也可以令你在写代码的时候,心情 ...

  6. 安装配置postgreSQL+pgcli+pgadmin3

    记录了postgreSQL数据库的完整的安装配置过程,以及postgreSQL的pgcli命令行智能提醒扩展,pgadmin3图形化管理客户端的配置安装.此postgresql是bigsql版安装详情 ...

  7. Goclipse的Eclipse插件包安装升级地址

    http://goclipse.github.io/releases/ Eclipse Software Site for Goclipse This URL is an Eclipse softwa ...

  8. Nancy使用Razor视图引擎时,提示对C:\Windows\temp 没有权限访问的问题

    Nancy下使用Razor视图需要添加DLL文件引用,通过Nuget安装: 发布网站,在IIS上建立站点后,提示错误:对C:\Windows\temp\XXXX 的访问被拒绝(在VS里F5调试的时候没 ...

  9. Visio中锁定元件

    若要进行形状保护,需要能看到“开发工具”选项卡.默认情况下,该选项卡是隐藏的. 查看“开发工具”选项卡 单击“文件”选项卡. 单击“选项”. 单击“高级”,然后向下滚动到“常规”部分. 选择“以开发人 ...

  10. SQL Server ->> PERCENTILE_CONT、PERCENTILE_DISC 和 PERCENT_RANK 函数

    PERCENTILE_CONT和PERCENTILE_DISC都是为了计算百分位的数值,比如计算在某个百分位时某个栏位的数值是多少.他们的区别就是前者是连续型,后者是离散型.CONT代表continu ...