Train Problem I--hdu1022(栈)
Train Problem I
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 25817 Accepted Submission(s): 9752
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<stdio.h>
#include<string.h>
#include<stack>
using namespace std;
char a[],b[];
int c[];
int main()
{
int n,i,j,k;
stack<char>s;//初始化一个栈
while(scanf("%d",&n)!=EOF)
{
getchar();
scanf("%s%s",a,b);
memset(c,-,sizeof(c));
while(!s.empty())
s.pop();
i=j=k=;
while(i<n)
{
s.push(a[i++]);
c[j++]=;
while(!s.empty()&&s.top()==b[k])//为什么要判断是否为空栈?这个是为了跳出while循环,如果是空栈了。就没栈顶了,没比较的意义了!
{
k++;
c[j++]=;
s.pop();//消栈
}
}
if(!s.empty())
{
printf("No.\n");//如果栈不为空,就是没消完
printf("FINISH\n"); }
else
{
printf("Yes.\n");
for(i=;i<j;i++)
{
if(c[i]==)
printf("in\n");
else if(c[i]==)
printf("out\n"); }
printf("FINISH\n");
}
}
return ;
}
Train Problem I--hdu1022(栈)的更多相关文章
- 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 ...
- (stack)Train Problem I hdu1022
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(栈的操作规则)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1022 Train Problem I Time Limit: 2000/1000 MS (Java/Ot ...
- hdu1022 Train Problem I---模拟栈
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1022 题目大意: 车的进出站问题,先给出N个火车,再按序列一的方式进站,判断能否以序列二的方式出站,若 ...
- HDU 1022 Train Problem I(栈模拟)
传送门 Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of st ...
- HDOJ/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 1022 栈模拟
题目大意: 给你一个n 代表有n列 火车, 第一个给你的一个字符串 代表即将进入到轨道上火车的编号顺序, 第二个字符串代表的是 火车出来之后到顺序, 分析一下就知道这,这个问题就是栈, 先进后出吗, ...
- hdu 1022 Train Problem I(栈)
#include<iostream> #include<vector> #include<cstring> #include<string> #incl ...
随机推荐
- 解决图片元素下多余空白的BUG
1.将图片转换为块级对象 即,设置img为“display:block;”.在本例中添加一组CSS代码:“#sub img {display:block;}”. 2.设置图片的垂直对齐方式 ...
- php 程序员的历程
今天一朋友该找工作了. 问了我好多 我整理了下 希望有些帮助 以下内容纯属个人感觉如果有不恰当的地方请忽略.... 我做的是项目的包工 就是把销售拿下的项目整合后给我们实现功能. --------- ...
- 《Python基础篇》之初识Python一
Python简介 python的创始人为吉多·范罗苏姆(Guido van Rossum).1989年的圣诞节期间,吉多·范罗苏姆为了在阿姆斯特丹打发时间,决心开发一个新的脚本解释程序,作为ABC语言 ...
- Parallel并行编程
Parallel并行编程 Parallel并行编程可以让我们使用极致的使用CPU.并行编程与多线程编程不同,多线程编程无论怎样开启线程,也是在同一个CPU上切换时间片.而并行编程则是多CPU核心同时工 ...
- iOS开发之网络篇-各种网络状态码
1xx消息 这一类型的状态码,代表请求已被接受,需要继续处理.这类响应是临时响应,只包含状态行和某些可选的响应头信息,并以空行结束.由于HTTP/1.0协议中没有定义任何1xx状态码,所以除非在某些试 ...
- Dropbox 用什么语言开发的?(Python在各个平台都是全能的,特别是有PyObjC真没想到)
Dropbox 绝大部分是用 Python 开发的.用到 Python 的地方有:服务器后台.客户端.Dropbox 网页版前段.API 后台.数据分析. 在服务器端.桌面版客户端使用的是 Pytho ...
- codecomb 2086【滑板鞋】
题目背景 我的滑板鞋时尚时尚最时尚 回家的路上我情不自禁 摩擦 摩擦 在这光滑的地上摩擦 月光下我看到自己的身影有时很远有时很近 感到一种力量驱使我的脚步 有了滑板鞋天黑都不怕 题目描述 你在魅力之都 ...
- 学DSP(二):目标芯片28335,GO!
28335开发板有了,之前没有用过TI的片子,还是先看看这个东西是啥东西. 进入28335的中文网页: http://www.ti.com.cn/product/cn/tms320f28335 ...
- 锁sql server锁
锁的概述 一. 为什么要引入锁 多个用户同时对数据库的并发操作时会带来以下数据不一致的问题: 丢失更新A,B两个用户读同一数据并进行修改,其中一个用户的修改结果破坏了另一个修改的结果,比如订票系统 脏 ...
- Contains Duplicate 解答
Question Given an array of integers, find if the array contains any duplicates. Your function should ...