HDU_1022
题目:



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 <iostream>
#include <stack>
#include <string>
#include <bits/stdc++.h>
using namespace std; #define IN 1
#define OUT 0
string a,b;
#define MAX_NUM 100100 int sep[MAX_NUM]; int main(int argc, char const *argv[])
{
int n;
while(cin >> n >> a >> b){
stack<char> s;
int i = , j = , k = ;
s.push(a[]);
sep[k++] = IN;
while(i < n && j < n){
if(s.size() != && s.top() == b[j]){
j++;
s.pop();
sep[k++] = OUT;
}else{
s.push(a[++i]);
sep[k++] = IN;
}
}
if(i == n){//如果i==n表示栈顶元素不等于序列2当前元素,且序列1中元素都已经入过栈,判断不能得到序列2一样的答案。
cout << "No." << endl;
}else{
cout << "Yes." << endl;
for (int i = ; i < k; ++i)
{
if(sep[i]){
cout << "in" << endl;
}
else{
cout << "out" << endl;
}
}
}
cout << "FINISH" << endl;
}
return ;
}
HDU_1022的更多相关文章
随机推荐
- webpack(3)--Output
Output output配置如何输出最终想要的代码,output是一个object里面包含一系列配置. 1. filename output.filename配置输出文件的名称,为string类型, ...
- 解决Sybase PowerDesigner 数据库设计中 Name 自动填充Code
在使用 Sybase PowerDesigner 进行数据库设计时,为了理清思路,需要将name改为中文名称,但是这个软件会自动将name填 充为code,可以通过如下配置修改: 选择tools-&g ...
- 经典算法 Morris遍历
内容: 1.什么是morris遍历 2.morris遍历规则与过程 3.先序及中序 4.后序 5.morris遍历时间复杂度分析 1.什么是morris遍历 关于二叉树先序.中序.后序遍历的递归和非递 ...
- JQ-用户注册用到的图形验证码,短信验证码点击事件,切换active类
// 点击切换图形验证码 页面加载完后执行,类似window.onload $(function () { var imgCaptcha = $(".img-captcha"); ...
- PY3 周总结 第一周
1. Python的三大特点是什么? 答:解释型.动态类型(运行期间才做数据类型检查).强类型定义(一个变量只能存储一种类型的数据).[See More] 2. 应该使用Python2 还是 Pyth ...
- elt区间分布
select DATE_FORMAT(CURDATE(),'%Y%m%d') DateId,elt(interval(curnum,0, 10000,20000,30000,40000,50000, ...
- activemq的学习
https://blog.csdn.net/csdn_kenneth/article/category/7352171/1
- HtmlRowCreated关于e.Row.Cells[0]的获取和设置
获取采用: cmd2.Parameters.AddWithValue("@xh", e.GetValue("学号").ToString().Trim()); ...
- 从Chrome 69.0 版本起,Flash权限受到进一步限制,默认仅在当前浏览器会话有效。
# 69.0 之后的版本 ## 从Chrome 69.0 版本起,Flash权限受到进一步限制,默认仅在当前浏览器会话有效.关闭Enable Ephemeral Flash Permissions , ...
- ant 注意
nt文件在部署时,如果控制台出现乱码则需要调整语言. 高版本eclipse在jdk高版本中已经植入了ant的部署.因此不需要单独配置ant.jar. 如果版本低,可下载ant插件,或者下载ant的工具 ...