传送门: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:
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long LL;
  4. int main()
  5. {
  6. int n,i,j;
  7. string str1,str2;
  8. while(cin>>n>>str1>>str2)
  9. {
  10. stack<char> s;
  11. vector<string> v;
  12. for( i=,j=;i<n&&j<n;i++)
  13. {
  14. s.push(str1[i]);//元素进栈
  15. v.push_back("in");//字符压进容器
  16. while(s.top()==str2[j])//匹配
  17. {
  18. if(!s.empty())
  19. {
  20. s.pop();
  21. v.push_back("out");
  22. }
  23. j++;
  24. if(s.empty())
  25. break;
  26. }
  27. }
  28. if(j==n)//判断依据
  29. {
  30. printf("Yes.\n");
  31. for(i=;i<v.size();i++)
  32. cout<<v[i]<<endl;
  33. cout<<"FINISH"<<endl;
  34. }else
  35. {
  36. cout<<"No."<<endl<<"FINISH"<<endl;
  37. }
  38. }
  39. return ;
  40. }

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. java读取txt文件,对字符串进行操作后导出txt文件

    嘿嘿,代码略为简单,不再多做解释,直接上码! package org.lq.com.util; import java.io.File; import java.io.InputStreamReade ...

  2. jasperreports+iReport+jatoolsPrinter制作报表笔记

    此文章是基于 EasyUI+Knockout实现经典表单的查看.编辑 一. 准备工作 1. 点击此下载相关的文件,并把 ims 文件夹放到 ims 工程对应的路劲下 2. 参考网址:杰创打印控件 二. ...

  3. 读EntityFramework.DynamicFilters源码_心得_示例演示02

    上次对EntityFramework.DynamicFilters整体的项目结构有了一个认识,这次我们就通过阅读说明文档,示例项目,和单元测试,来动手构建一个我们的体验项目,通过对动态过滤器的使用,使 ...

  4. window.open在Safari中不能打开的问题

    在调移动支付问题的时候遇到过,用window.open打开一个微信支付链接,唤醒移动支付,在IOS下死活唤醒不了,是js代码冲突问题...是click事件IOS下不兼容问题...最后定位到window ...

  5. Can't read stdin: end of file found

    问题是在我修改svn的账号和密码后出现的,因为百度出来的情况只有一种答案,所以记录一下我的情况,给其他人多一种排查思路.问题根源是,由于该版本库只有一个账号,更改了账号密码,没有同步修改post-co ...

  6. 51Nod 算法马拉松22 开黑记

    这是一场惨烈的开黑大战,始于全机房开黑指望刷进rank前十拿钱的壮志,终于被各路神犇怒踩成rank20,差点200点头盾不保的落魄,想起将近一年前ad和zcg等学长挤进rank10的壮举,不由得唏嘘, ...

  7. [转]Windows下Redis缓存服务器的使用 .NET StackExchange.Redis Redis Desktop Manager

    转自:http://www.cnblogs.com/oppoic/p/6165581.html Redis缓存服务器是一款key/value数据库,读110000次/s,写81000次/s,因为是内存 ...

  8. WINDOWS API ——CREATETOOLHELP32SNAPSHOT——查找进程

    原文:http://www.cnblogs.com/wind-net/archive/2012/10/26/2741458.html //根据进程名获取进程ID DWORD GetPidByProce ...

  9. C语言数组指针(指向数组的指针)

    注意:数组指针的定义,与指针数组的区别 转载:http://c.biancheng.net/cpp/biancheng/view/162.html 指向多维数组元素的指针变量 ① 指向数组元素的指针变 ...

  10. Surrounded Regions [未完成]

    思路完全一样 AC的代码: class Solution { private: struct Point { int x, y; Point(int _x, int _y):x(_x), y(_y) ...