HDU 1022 Train Problem I(栈的操作规则)
传送门: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



3 123 312
in
in
in
out
out
out
FINISH
No.
FINISH
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.".
所以不是反序才行 可以进到一半就出的
- #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(栈的操作规则)的更多相关文章
- 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(数据结构,栈,递归,dfs)
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- hdu 1022 Train Problem I【模拟出入栈】
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- 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 ...
- HDU - 1022 Train Problem I STL 压栈
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1022 Train Problem I(栈的应用+STL)
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU 1022 Train Problem I[给出两个长n的串,入栈和出栈顺序,判断入栈顺序是否可以匹配出栈顺序]
Train Problem I 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 As the new term comes, the Ignatius Train Sta ...
- HDU 1022 Train Problem I 模拟栈题解
火车进站,模拟一个栈的操作,额外的栈操作,查看能否依照规定顺序出栈. 数据量非常少,故此题目非常easyAC. 直接使用数组模拟就好. #include <stdio.h> const i ...
- HDU 1022 Train Problem I
A - Train Problem I Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
随机推荐
- java读取txt文件,对字符串进行操作后导出txt文件
嘿嘿,代码略为简单,不再多做解释,直接上码! package org.lq.com.util; import java.io.File; import java.io.InputStreamReade ...
- jasperreports+iReport+jatoolsPrinter制作报表笔记
此文章是基于 EasyUI+Knockout实现经典表单的查看.编辑 一. 准备工作 1. 点击此下载相关的文件,并把 ims 文件夹放到 ims 工程对应的路劲下 2. 参考网址:杰创打印控件 二. ...
- 读EntityFramework.DynamicFilters源码_心得_示例演示02
上次对EntityFramework.DynamicFilters整体的项目结构有了一个认识,这次我们就通过阅读说明文档,示例项目,和单元测试,来动手构建一个我们的体验项目,通过对动态过滤器的使用,使 ...
- window.open在Safari中不能打开的问题
在调移动支付问题的时候遇到过,用window.open打开一个微信支付链接,唤醒移动支付,在IOS下死活唤醒不了,是js代码冲突问题...是click事件IOS下不兼容问题...最后定位到window ...
- Can't read stdin: end of file found
问题是在我修改svn的账号和密码后出现的,因为百度出来的情况只有一种答案,所以记录一下我的情况,给其他人多一种排查思路.问题根源是,由于该版本库只有一个账号,更改了账号密码,没有同步修改post-co ...
- 51Nod 算法马拉松22 开黑记
这是一场惨烈的开黑大战,始于全机房开黑指望刷进rank前十拿钱的壮志,终于被各路神犇怒踩成rank20,差点200点头盾不保的落魄,想起将近一年前ad和zcg等学长挤进rank10的壮举,不由得唏嘘, ...
- [转]Windows下Redis缓存服务器的使用 .NET StackExchange.Redis Redis Desktop Manager
转自:http://www.cnblogs.com/oppoic/p/6165581.html Redis缓存服务器是一款key/value数据库,读110000次/s,写81000次/s,因为是内存 ...
- WINDOWS API ——CREATETOOLHELP32SNAPSHOT——查找进程
原文:http://www.cnblogs.com/wind-net/archive/2012/10/26/2741458.html //根据进程名获取进程ID DWORD GetPidByProce ...
- C语言数组指针(指向数组的指针)
注意:数组指针的定义,与指针数组的区别 转载:http://c.biancheng.net/cpp/biancheng/view/162.html 指向多维数组元素的指针变量 ① 指向数组元素的指针变 ...
- Surrounded Regions [未完成]
思路完全一样 AC的代码: class Solution { private: struct Point { int x, y; Point(int _x, int _y):x(_x), y(_y) ...