题意是给定火车进站的序列和出站的序列,问能否完成转换,若能输出过程。

和另一道以火车进站为背景的栈应用题类似,但增加了对于过程的输出,只需要多记录一下进出站顺序即可。

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. std::ios::sync_with_stdio(false);
  6. int n,pos,cnt,vis[];
  7. stack<char> q;
  8. char come[],go[];
  9. while(cin >> n)
  10. {
  11. cin >> come >> go;
  12. pos = ;
  13. cnt = ;
  14. while(!q.empty()) q.pop();
  15. memset(vis,-,sizeof(vis));
  16. for(int i = ; i < n; i++)
  17. {
  18. vis[cnt++] = ;
  19. q.push(come[i]);
  20. while(!q.empty()&&q.top() == go[pos])
  21. {
  22. q.pop();
  23. pos++;
  24. vis[cnt++] = ;
  25. }
  26. }
  27. if(pos==n)
  28. {
  29. cout << "Yes.\n";
  30. for(int i = ; i < cnt; i++)
  31. {
  32. if(vis[i]) cout << "in\n";
  33. else cout << "out\n";
  34. }
  35. }
  36. else cout << "No.\n";
  37. cout << "FINISH\n";
  38. }
  39. return ;
  40. }

HDU 1022(火车过站 栈)的更多相关文章

  1. HDU 1022 火车进站【栈】

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

  2. Hdu 1022 Train Problem I 栈

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

  3. HDU 1022 Train Problem I 用栈瞎搞

    题目大意:有n辆火车,按一定的顺序进站(第一个字符串顺序),问是否能按规定的顺序出站(按第二个字符串的顺序出去),如果能输出每辆火车进出站的过程. 题目思路:栈的特点是先进后出,和题意类似,还有有一种 ...

  4. hdu 1022 Train Problem I(栈)

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

  5. HDU 1022 Train Problem I

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

  6. 华为OJ—火车进站(栈,字典排序)

    http://career-oj.huawei.com/exam/ShowSolution?method=SolutionApp&id=2282 给定一个正整数N代表火车数量,0<N&l ...

  7. hdu 5033 buiding(单调栈)

    hdu 5033 buiding(单调栈) 某年某月某天,马特去了一个小镇.这个小镇如此狭窄,以至于他可以把小镇当作一个枢纽.在镇上有一些摩天大楼,其中一栋位于xi,高度为hi.所有的摩天大楼位于不同 ...

  8. 2017 省赛选拨 火车入站 CSU 1757 模拟

    1757: 火车入站 Submit Page   Summary   Time Limit: 1 Sec     Memory Limit: 128 Mb     Submitted: 512     ...

  9. Train Problem I hdu 1022(栈)

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

随机推荐

  1. C++ 中 const、volatile、mutable的用法

    @2019-01-14 [小记] C++中const.volatile.mutable的用法

  2. thinkphp5 上传服务器后 Access denied

    服务器报 Access denied,要么报 No input files,但是在网上查了查说是将 PHP 的cgi.fix_pathinfo 改成 1 即可,但是改成 1 显然是有解析漏洞的,尝试寻 ...

  3. 在views中引用UserProfile报错RuntimeError: Model class apps.users.models.UserProfile doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

    如图报错,在settings中,该加的也加了啊! 显然类似于网上最容易遇到的解决方案如下图,是没有任何意义的 只要在view中有 from .models import UserProfile,Ver ...

  4. python pip NameError:name 'pip' is not defined”

    https://www.jianshu.com/p/f57f98ebcb21 问题: 如果直接在命令行里面输入pip或者pip3,提示:(如图1) “NameError:name 'pip' is n ...

  5. Oracle的DQL

    基本查询: 链接语句: sqlplus scott/tiger@192.168.56.101:1521/orcl SQL> --清屏 SQL> host cls (host clear) ...

  6. TestNg1. 基本介绍注解介绍和如何让在maven中引用

    1.更适合测试人员,有很多的套件. maven中引用: <!-- https://mvnrepository.com/artifact/org.testng/testng --><d ...

  7. 原生JS实现$.ajax

    function ajax(obj){ obj=obj||{}; obj.type=(obj.type||'GET').toUpperCase(); obj.dataType=obj.dataType ...

  8. aliyun centos7 挂载云盘

    买了云盘,在哪里放着,也没有用到,今天把她挂上去吧! 1.查看SSD云盘sudo fdisk -l 可以看到SSD系统已经识别为/dev/vdb 2.格式化云盘sudo mkfs.ext4 /dev/ ...

  9. (map)What Are You Talking About hdu1075

    What Are You Talking About Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/204800 K ...

  10. 使用 windows 下的 secureCRT 软件的 通过 sftp 上传和下载文件到远端 linux 设备

    secureCRT 按下ALT+P就开启新的会话进行ftp操作. 输入:help命令,显示该FTP提供所有的命令 pwd:  查询linux主机所在目录(也就是远程主机目录) lpwd: 查询本地目录 ...