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 ...
随机推荐
- android自定义activity
今天公司有个需要需要自动弹出界面,而dialog又不符合要求,所以自定义的一个activity的样式 首先在androidmainfest.xml上注册你的activity <activity ...
- 打印frame
NSLog(@"%@",NSStringFromCGRect(switch.frame)); 或者 CFShow(NSStringFromCGRect(switch.frame)) ...
- 【读书笔记】iOS-使用Web Service-基于客户端服务器结构的网络通信(一)
Web Service技术是一种通过Web协议提供服务,保证不同平台的应用服务可以互操作,为客户端程序提供不同的服务. 目前3种主流的Web Service实现方案用:REST,SOAP和XML-RP ...
- C++语言-06-文件操作
C语言文件操作 C++语言是C语言的超集,是在C语言的基础上增加了面向对象的特性而创造出来的,最初被命名为带类的C.所以C++语言中包含了C语言的思想,如:C++语言中文件操作的原理与步骤与C语言基本 ...
- JavaScript Patterns 6.1 Classical Versus Modern Inheritance Patterns
In Java you could do something like: Person adam = new Person(); In JavaScript you would do: var ada ...
- sql server 警报管理,实时监听数据库动向,运筹帷幄之中
工作这么多年了,无论是身边的同学还是同事,发现只要搞程序员的都有一个通病---懒.懒到谁都不愿意加班,尤其是"义务"加班.即使大家都不愿意加班,但是很多时候项目赶着上线或者上线之后 ...
- Linux JDK 安装
1,下载JDK(Linux版) 官网下载:http://www.oracle.com/technetwork/java/javase/downloads/index.html 2, 建立java目录 ...
- x01.os.13: 文件系统
停了两天电,忽然得空闲.找来破吉他,已然不成弦. 丁丁当当敲,敲到电来到.为把时间捡,熬夜三四点. 从我的置顶随笔 x01.Lab.Download 中下载 x01.os.12.t ...
- Java里面的转义字符
转义字符是指,用一些普通字符的组合来代替一些特殊字符,由于其组合改变了原来字符表示的含义,因此称为“转义”. 常见的转义字符: \n 回车(\u000a) \t 水平制表符(\u0009) \b 空格 ...
- FTP定时批量下载文件(SHELL脚本及使用方法 )
1. 脚本实例 将以下脚本保存为 getftp.sh #!/bin/bash datesign=`date -d -95day +%Y%m%d` ftp -nv 12.2.2.28 << ...