HDU 1022 Train Problem I
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
Input
Output
Sample Input
3 123 312
Sample Output
in
in
in
out
out
out
FINISH
No.
FINISH
Hint
- 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.".
- 题意大体是 询问出栈入栈是否符合栈的规定,如果符合 输入顺序;否则no。最后finsh
- 代码
- #include<cstdio>
- #include<cstdlib>
- #include<cstring>
- #include<algorithm>
- #include<vector>
- #include<queue>
- #include<stack>
- #include<set>
- #include<iostream>
- #include<bits/stdc++.h>
- #define ll long long
- using namespace std;
- int n,i,j,k,flag[];
- char s1[],s2[];
- int main()
- {
- stack <char> s;
- while(~scanf("%d",&n)){
- memset(flag,-,sizeof(flag));
- cin>>s1>>s2;
- while(!s.empty()) s.pop();
- j=,k=;
- for(int i=;i<n;i++){
- s.push(s1[i]);
- flag[k++]=;
- while(!s.empty()&&s.top()==s2[j])
- flag[k++]=,s.pop(),j++;
- }
- if(j==n){
- printf("Yes.\n");
- for(int i=;i<k;i++)
- if(flag[i]) printf("in\n");
- else printf("out\n");
- printf("FINISH\n");
- }else{
- printf("No.\n");
- printf("FINISH\n");
- }
- }
- return ;
- }
HDU 1022 Train Problem I的更多相关文章
- 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) ...
- 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(数据结构,栈,递归,dfs)
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- hdu 1022 Train Problem
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- HDU 1022 Train Problem I[给出两个长n的串,入栈和出栈顺序,判断入栈顺序是否可以匹配出栈顺序]
Train Problem I 时间限制:3000 ms | 内存限制:65535 KB 难度:2 描述 As the new term comes, the Ignatius Train Sta ...
随机推荐
- UI复习
UIButton的状态 • normal(普通状态) ➢ 默认情况 ➢ 对应的枚举常量:UIControlStateNormal • highlighted(高亮状态) ➢ 按钮被按下去的时候(手指还 ...
- iOS-UIScrollView和UIPageControl的综合实力,滚动图,轮播图
本代码主要实现图片之间的切换 目录结构 代码 ViewController.m文件 #import "ViewController.h" @interface ViewContro ...
- JSP中request getParameter和getAttribute不同(转载)
(1)request.getParameter()取得是通过容器的实现来取得通过类似post,get等方式传入的数据,,request.setAttribute()和getAttribute()只是在 ...
- Asp.net WebPages框架运行原理浅析(转)
在Asp.net4和4.5中,新增了WebPages Framework,编写页面代码使用了新的Razor语法,代码更加的简洁和符合Web标准,编写方式更接近于PHP和以前的Asp,和使用 WebFo ...
- mysql一些小技巧
1 强制命中索引:force index 某些时候查询,索引会失效,可以进行强制命中索引 2 group_concat 能将相同的行组合起来. 当然,我推荐这种操作可以在代码中操作,如果必须在特定情况 ...
- 基于分布式、服务化的maven项目文件规划
引言 此文不是纯粹介绍maven概念,而是介绍一个具体的maven项目文件规划 这个规划可能适合于研发比较复杂的业务,这些业务有分布式和服务化的需要. 这个规划能够解决因为分布式和服务化要求而引起的项 ...
- PMBOK(第五版)学习笔记二-十大知识领域(P87)
五大项目管理过程组:启动.规划.执行.监控.收尾过程组 十大知识领域是:项目整合管理.项目范围管理.项目时间管理.项目成本管理.项目质量管理.项目人力资源管理.项目沟通管理.项目风险管理.项目采购管理 ...
- C#语言基础-类——string增加内容
.split() 分离——属于string类 Console.Write("请输入姓名和学号(**-****):"); strin ...
- 挖一挖C#中那些我们不常用的东西之系列(3)——StackTrace,Trim
时间太快了,三月又要过去了,告别一下...继续期待生死未卜的四月,今天我们继续挖一挖. 一: Environment.StackTrace 可能我们看到最多的就是catch中的e参数,里面会有一个St ...
- Windows下用Codeblocks建立一个最简单的DLL动态链接库
转自:http://blog.csdn.net/wangwei_cq/article/details/8187576 来源:http://hi.baidu.com/hellosim/item/9ae4 ...