Train Problem I hdu 1022(栈)
http://acm.split.hdu.edu.cn/showproblem.php?pid=1022
题意:给出火车的进站与出站顺序,判断是否可以按照给出的出站顺序出站。
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <math.h> using namespace std; #define INF 0x3f3f3f3f
const int maxn = ;
typedef long long LL; int main()
{
int n;
int a[];
char str1[], str2[]; while(scanf("%d%s%s", &n, str1, str2)!=EOF)
{
stack<char>Q;
Q.push(str1[]); memset(a, , sizeof(a));
a[] = ; int i=;
int j=;
int k=; while(i<n && j<n)
{
if(Q.size() && Q.top()==str2[j])
{
a[++k]=;
Q.pop();
j++;
}
else
{
Q.push(str1[++i]);
a[++k]=;
}
} if(k!=*n) printf("No.\n");
else
{
printf("Yes.\n"); for(int i=;i<=k;i++)
if(a[i])
printf("in\n");
else
printf("out\n"); }
printf("FINISH\n");
}
return ;
}
Train Problem I hdu 1022(栈)的更多相关文章
- HDU - 1022 Train Problem I STL 压栈
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- Train Problem II HDU 1023 卡特兰数
Problem Description As we all know the Train Problem I, the boss of the Ignatius Train Station want ...
- HDU 1022 Train Problem I (数据结构 —— 栈)
Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot o ...
- HDU Train Problem I (STL_栈)
Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot o ...
- Train Problem I (HDU 100题纪念)
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- Train Problem I(模拟栈)
题意:模拟栈,试问使用2个栈,能否使得串1变为串2 思路:模拟,经典问题,注意只要相同的元素放到栈顶后就不会再移动了,只需要考虑剩下的元素,因此每次只考虑一个元素的进入方式. #include< ...
- HDU 1022 Train Problem I(栈的操作规则)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1022 Train Problem I Time Limit: 2000/1000 MS (Java/Ot ...
- 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 栈
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
随机推荐
- ImageMagick Windows x64下的安装
在windows下安装ImageMagick时,安装的版本一定要跟php的插件是同一个的,包含vc++编译的版本. 我使用的是ImageMagick-6.9.3-7-Q16-x64-dll.exe 和 ...
- [solr] - 索引数据删除
删除solr索引数据,使用XML有两种写法: 1) <delete><id>1</id></delete> <commit/> 2) < ...
- HackerRank "Kitty and Katty"
It's more of a brain-teaser than a Game Theory problem.. #!/bin/python3 T = int(input().strip()) for ...
- 一个很奇怪的重复链接lib的问题
早上在调一个程序的时候感觉非常奇怪,就是数据在初始化的时候会失败,后来发现是获取一个数据的时候出错了 假设我们又一个config.lib,sql.dll和main.exe 因为数据库在打开数据库的时候 ...
- 【uTenux实验】信号量
信号量(semaphore)是一个用来指示可用的资源并将可用资源的数量以数值的形式表示出来的对象.当使用一组资源时,信号量用来实现互斥控制和同步.uTenux提供了信号量出来的API,可以很方便地使用 ...
- UVA 1658 海军上将(拆点法+最小费用限制流)
海军上将 紫书P375 这题我觉得有2个难点: 一是拆点,要有足够的想法才能把这题用网络流建模,并且知道如何拆点. 二是最小费用限制流,最小费用最大流我们都会,但如果限制流必须为一个值呢?比如这题限制 ...
- python os.system()返回值判断
最近遇到os.system()执行系统命令的情况,上网搜集了一下资料,整理如下,以备不时之需,同时也希望能帮到某些人. 一.python中的 os.system(cmd)的返回值与linux命令返回值 ...
- Release时error c1083 无法打开包括文件
Release时error c1083 无法打开包括文件, 但Debug时没事. 项目里面包含了其实项目的头文件, 头文件目录就放在项目下面, 这个头文件里面调用其它头文件, 采用的是<xx/y ...
- webview中的页面兼容iphone6和6+
其实写这篇文章的本不该是我,而应该是开发ios的小伙伴,但作为一个前端,我想我还是有必要做一下记录的! 首先我想说下在iphone6或者6+中webview内嵌套的页面宽度已经不在是320px,而是3 ...
- MFCButton Memory leak(内存泄露问题)
http://m.blog.csdn.net/blog/haoekin/8851219 1.无法显示右边箭头的问题 无论怎么折腾都没显示不出来,微软给的示例又能显示,度娘和谷歌也都不知道,经过不断地探 ...