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 ...
随机推荐
- HTML5简单入门系列(四)
前言 今天这篇内容主要讲述HTML 5 Web Worker(一种支持前端js多线程的技术). 工作线程(Web Worker) web worker介绍 W3C 在 HTML5 的规范中提出了工作线 ...
- Pie(hdu 1969 二分查找)
Pie Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submiss ...
- Keil C -WARNING L15: MULTIPLE CALL TO SEGMENT
1.第一种错误信息 ***WARNING L15: MULTIPLE CALL TO SEGMENT SEGMENT: ?PR?_WRITE_GMVLX1_REG?D_GMVLX1 CALLER1: ...
- C# System.Uri类_获取Url的各种属性_文件名_参数_域名_端口等等
System.Uri类用于处理Uri地址信息,常用到它的地方有,相对Uri地址转绝对Uri地址,获取Uri的某部分信息等等,可以说是一个非常有用的类. 一.属性 AbsolutePath 获取 URI ...
- UESTC_酱神赏花 2015 UESTC Training for Dynamic Programming<Problem C>
C - 酱神赏花 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 262143/262143KB (Java/Others) Submi ...
- 【LeetCode练习题】Maximum Depth of Binary Tree
Maximum Depth of Binary Tree Given a binary tree, find its maximum depth. The maximum depth is the n ...
- InternetExplorer 表单及用户名密码提交
陆ftp或者其他类似需要输入密码的站点,可以在url中直接输入用户名密码,格式为: ftp://username:password@url 另外一种情况是,如果是表单提交的也可以通过url填写,如: ...
- 图片旋转+剪裁js插件(兼容各浏览器) « 张鑫旭-鑫空间-鑫生活
图片旋转+剪裁js插件(兼容各浏览器) « 张鑫旭-鑫空间-鑫生活 图片旋转+剪裁js插件(兼容各浏览器) by zhangxinxu from http://www.zhangxinxu.com 本 ...
- MySQL Workbench导出数据库
步骤: 1. 打开mysql workbench,进入需要导出的数据库,点击左侧栏的[Management]tab键. 2. 点选要输出的数据库 点击[Data Export] 选在要输出的数据库 选 ...
- Eclipse文件覆盖问题
window-preferences-General-Search找到第一行的一个选项 Reuse editors to show matches他的意思是说在同一个编辑里面显示匹配的文件,如果后面有 ...