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的更多相关文章
随机推荐
- solr中facet及facet.pivot理解
Facet['fæsɪt]很难翻译,只能靠例子来理解了.Solr作者Yonik Seeley也给出更为直接的名字:导航(Guided Navigation).参数化查询(Paramatic Searc ...
- ajax json用法 上传文件 登录
1. json json 是一种数据结构 跨平台跨语言 1. python中json数据的转换 1.数据类型 字符串 数字 布尔值 列表 字典 None 2. 序列化 ...
- js的sort(0实现数组的排序
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- EF中GroupBy扩展方法的简单使用
public ActionResult ShopInfo() { ViewBag.ShopList = ShopService.GetEntities(x => x.IsDelete == fa ...
- License分类 + 引入开源软件时License的注意事项
License分类 GPL: linux.openJDK,openJFX,mysql 融合感染,单独子模块不感染(自己的模块与引入模块的通信方式是socket) openJDK(GNU General ...
- ganglia
A.lamp界面快速搭建---------------------------------------------------------------------------------------- ...
- CentOS7.3下yum练手安装Nginx,支持php5.4
yum install php php-devel 安装的是5.4 那么安装完毕了,怎么设置nginx和php 解析 1 添加nginx 默认主页index.php vim .../etc/ngin ...
- leetcode263
public class Solution { private bool Judge(int x) { ) { return false; } int bound = Convert.ToInt32( ...
- XE 创建 Active Form
XE6: http://docwiki.embarcadero.com/RADStudio/XE6/en/Generating_an_Active_Form_Based_on_a_VCL_Form h ...
- mysql 1292-Truncated incorrect double value
sql = "select id from company where date_year_month = %s" % "2017-3" 出错 将%s改为'%s ...