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 ...
随机推荐
- IOC和DI到底是什么?
在学习Spring框架的时候,我们总是能见到IOC这个单词,也时常听到DI这个词,那么他们分别是什么意思呢?接下来就讲讲个人对于这两个概念的理解 一.IOC和DI概念 IOC(控制反转):全称为: ...
- 模仿jquery的data
jquery中,有这个方法 var obj = {}; $.data(obj,'name','jake'); console.info($.data(obj,'name')); console.inf ...
- 车厢调度(train.cpp)
车厢调度(train.cpp) [问题描述] 有一个火车站,铁路如图所示,每辆火车从A驶入,再从B方向驶出,同时它的车厢可以重新组合.假设从A方向驶来的火车有n节(n<=1000) ...
- 前端之body标签中相关标签(一)
一 字体标签 字体标签包含:h1~h6.<font>.<u>.<b>.<strong><em>.<sup>.<sub& ...
- css设置一行显示,超出部分显示...
碰到一些介绍时候需要一行显示,然后超出部分用...替代 white-space: nowrap;不换行显示text-overflow: ellipsis;以...显示overflow: hidden; ...
- Unity创建或克隆对象 Instantiate()
//需要创建对象 GameObject prefab; //创建对象的规定位置或父物体 Transform tr; //创建出对象 Instantiate(prefab); //创建对象,并设定位置和 ...
- HTTP Status 500 - Handler processing failed; nested exception is java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config
今天在用idea搭建spring mvc时候报了这个错误,缺少jstl的依赖包.由于是使用的spring-core的依赖,而spring-core里面是有jstl的.这就郁闷了,最后是在自己的pom. ...
- SQL 截取字符
select SUBSTRING('123,abcdefg',charindex(',','123,abcdefg',0)+1,LEN('123,abcdefg')-charindex(',','12 ...
- javascript 匿名函数及闭包----转载
网上很多解释,我无法理解,我想知道原理...这篇文章应该可以透彻一点Query片段:view plaincopy to clipboardprint? (function(){ //这里忽略 ...
- win2008 svn 搬迁
公司说电脑不够用,要我们将本地开发用的服务器贡献出来给别人当办公电脑用..汗 将SVN从一个win2008服务器上搬迁到另一个win2008服务器上面. 先将服务器上面的配置好的svn 跟目录备份下来 ...