HDU 1022(火车过站 栈)
题意是给定火车进站的序列和出站的序列,问能否完成转换,若能输出过程。
和另一道以火车进站为背景的栈应用题类似,但增加了对于过程的输出,只需要多记录一下进出站顺序即可。
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- std::ios::sync_with_stdio(false);
- int n,pos,cnt,vis[];
- stack<char> q;
- char come[],go[];
- while(cin >> n)
- {
- cin >> come >> go;
- pos = ;
- cnt = ;
- while(!q.empty()) q.pop();
- memset(vis,-,sizeof(vis));
- for(int i = ; i < n; i++)
- {
- vis[cnt++] = ;
- q.push(come[i]);
- while(!q.empty()&&q.top() == go[pos])
- {
- q.pop();
- pos++;
- vis[cnt++] = ;
- }
- }
- if(pos==n)
- {
- cout << "Yes.\n";
- for(int i = ; i < cnt; i++)
- {
- if(vis[i]) cout << "in\n";
- else cout << "out\n";
- }
- }
- else cout << "No.\n";
- cout << "FINISH\n";
- }
- return ;
- }
HDU 1022(火车过站 栈)的更多相关文章
- HDU 1022 火车进站【栈】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1022 题目大意: 题目大概意思:有N辆火车,以序列1方式进站,判断是否能以序列2方式出栈.进站不一定 ...
- Hdu 1022 Train Problem I 栈
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1022 Train Problem I 用栈瞎搞
题目大意:有n辆火车,按一定的顺序进站(第一个字符串顺序),问是否能按规定的顺序出站(按第二个字符串的顺序出去),如果能输出每辆火车进出站的过程. 题目思路:栈的特点是先进后出,和题意类似,还有有一种 ...
- hdu 1022 Train Problem I(栈)
#include<iostream> #include<vector> #include<cstring> #include<string> #incl ...
- HDU 1022 Train Problem I
A - Train Problem I Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- 华为OJ—火车进站(栈,字典排序)
http://career-oj.huawei.com/exam/ShowSolution?method=SolutionApp&id=2282 给定一个正整数N代表火车数量,0<N&l ...
- hdu 5033 buiding(单调栈)
hdu 5033 buiding(单调栈) 某年某月某天,马特去了一个小镇.这个小镇如此狭窄,以至于他可以把小镇当作一个枢纽.在镇上有一些摩天大楼,其中一栋位于xi,高度为hi.所有的摩天大楼位于不同 ...
- 2017 省赛选拨 火车入站 CSU 1757 模拟
1757: 火车入站 Submit Page Summary Time Limit: 1 Sec Memory Limit: 128 Mb Submitted: 512 ...
- Train Problem I hdu 1022(栈)
http://acm.split.hdu.edu.cn/showproblem.php?pid=1022 题意:给出火车的进站与出站顺序,判断是否可以按照给出的出站顺序出站. #include < ...
随机推荐
- C++ 中 const、volatile、mutable的用法
@2019-01-14 [小记] C++中const.volatile.mutable的用法
- thinkphp5 上传服务器后 Access denied
服务器报 Access denied,要么报 No input files,但是在网上查了查说是将 PHP 的cgi.fix_pathinfo 改成 1 即可,但是改成 1 显然是有解析漏洞的,尝试寻 ...
- 在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 ...
- python pip NameError:name 'pip' is not defined”
https://www.jianshu.com/p/f57f98ebcb21 问题: 如果直接在命令行里面输入pip或者pip3,提示:(如图1) “NameError:name 'pip' is n ...
- Oracle的DQL
基本查询: 链接语句: sqlplus scott/tiger@192.168.56.101:1521/orcl SQL> --清屏 SQL> host cls (host clear) ...
- TestNg1. 基本介绍注解介绍和如何让在maven中引用
1.更适合测试人员,有很多的套件. maven中引用: <!-- https://mvnrepository.com/artifact/org.testng/testng --><d ...
- 原生JS实现$.ajax
function ajax(obj){ obj=obj||{}; obj.type=(obj.type||'GET').toUpperCase(); obj.dataType=obj.dataType ...
- aliyun centos7 挂载云盘
买了云盘,在哪里放着,也没有用到,今天把她挂上去吧! 1.查看SSD云盘sudo fdisk -l 可以看到SSD系统已经识别为/dev/vdb 2.格式化云盘sudo mkfs.ext4 /dev/ ...
- (map)What Are You Talking About hdu1075
What Are You Talking About Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 102400/204800 K ...
- 使用 windows 下的 secureCRT 软件的 通过 sftp 上传和下载文件到远端 linux 设备
secureCRT 按下ALT+P就开启新的会话进行ftp操作. 输入:help命令,显示该FTP提供所有的命令 pwd: 查询linux主机所在目录(也就是远程主机目录) lpwd: 查询本地目录 ...