1. #include<iostream>
  2. #include<vector>
  3. #include<cstring>
  4. #include<string>
  5. #include<stack>
  6. #include<map>
  7. using namespace std;
  8.  
  9. ];
  10. /*
  11. 栈的应用
  12. 若in[i]==out[j]则先进栈后立即出栈,此时只需i++,j++;
  13. 若in[i]!=out[j]检查栈首是否为out[j],若是,则出栈,并j++,否则将in[i]入栈,并j++
  14. i==n时,若栈不为空则说明任有火车未出栈,检查栈内元素==out[j++]   f[i]: 1表示进栈,0表示出栈
  15. 。。。。期末考试时不会做,遂记之
  16. */
  17. int main()
  18. {
  19. freopen("d:\\in.txt", "r", stdin);
  20. freopen("d:\\out.txt", "w", stdout);
  21. string in, out;
  22. int n;
  23. while(cin>>n)
  24. {
  25. ;
  26. cin>>in>>out;
  27. bool flag=true;
  28. , j=;
  29. stack<char>s;
  30. while(i<n) {
  31. if(in[i]==out[j]){
  32. i++; j++;
  33. f[cur++]=;
  34. f[cur++]=;
  35. }else if(!s.empty()){
  36. char first=s.top();
  37. if(first==out[j]){
  38. j++;
  39. s.pop();
  40. f[cur++]=;
  41. }else{
  42. s.push(in[i++]);
  43. f[cur++]=;
  44. }
  45. }else {
  46. s.push(in[i++]);
  47. f[cur++]=;
  48. }
  49. }
  50. while(!s.empty()){
  51. char first=s.top();
  52. f[cur++]=;
  53. s.pop();
  54. if(first != out[j++]){
  55. flag=false;
  56. break;
  57. }
  58. }
  59. if(flag){
  60. cout<<"Yes."<<endl;
  61. ; i<cur; i++){
  62. )cout<<"in"<<endl;
  63. else cout<<"out"<<endl;
  64. }
  65. cout<<"FINISH"<<endl;
  66. } else {
  67. cout<<"No.\nFINISH"<<endl;
  68. }
  69. }
  70. ;
  71. }

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(栈的操作规则)

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

  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(数据结构,栈,递归,dfs)

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

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

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

  9. HDU 1022 Train Problem I

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

  10. hdu 1022 Train Problem

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

随机推荐

  1. DuiLib 中滚动条不显示的问题

    DuiLib 很好用,同时在没有完全理解源码的前提下,坑也不少,比如今天遇到的添加滚动条不显示... 情况是这样的,将一个页面作为Tab控件的其中一页,为了代码不窝在一起,就没有在CreateCont ...

  2. 使用ab对站点进行压力测试

    测试指令: window下: E:\wamp\bin\apache\Apache2.2.21\bin> .\ab -V  //查看是否按照了ab:(V 大写) E:\wamp\bin\apach ...

  3. 能量项链AC了

    我打算写出一个尽量看起来像是人话的解题报告. 然而这道题我还是[虽然AC但不会做] OYZ

  4. c# 操作xml之xmlReader

    xmlReader的名称空间using System.Xml; xmlReader是通过流的方式来读取xml文件的内容 <?xml version="1.0" encodin ...

  5. gulp插件大全

    原文:http://www.mamicode.com/info-detail-517085.html No.1.run-sequence   作用:让gulp任务,可以相互独立,解除任务间的依赖,增强 ...

  6. ligerUI实现分页

    在公司实习看到公司框架里使用了ligerUI的grid进行分页,个人感觉挺好用的,自己摸索着实现了一遍记录下来 简单来说,liger grid 就是提交准备好的数据到指定的目标请求数据,拿到数据以后, ...

  7. UltraEdit-32文本编辑器软件 23.20.0.28 中文版

    软件名称: UltraEdit-32文本编辑器软件软件语言: 简体中文授权方式: 共享软件运行环境: Win 32位/64位软件大小: 21.5MB图片预览: 软件简介:UltraEdit 是一个功能 ...

  8. HTTP状态码(HTTPStatusCode)

    HTTP状态码(HTTPStatusCode) 祓焘铺 布稍酡 盛坭馆 距熏屿砥 女装出来扔了套到床上然后自己穿了套 跎徨鼻卩 权术埭 悌颞 蔹咽诹ㄒ 椿酣漂作 钱是小事关键是没有老师耸了 ...

  9. Hive 常用函数

    参考地址:https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF 1. parse_url(url, partToExt ...

  10. dpkg -P <pkg>

    http://www.linuxquestions.org/questions/debian-26/how-do-i-get-rid-of-those-rc-packages-as-seen-in-d ...