hdu1022 模拟栈
Train Problem I
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 46887 Accepted Submission(s): 17593



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<iostream>
#include<stack>
#include<string.h>
#include<stdio.h>
using namespace std;
int main()
{
int n;
char a[],b[];
int c[];
while(cin>>n)
{
cin>>a;
cin>>b;
stack<char>s;
while(!s.empty())
s.pop();
int j=,num=;
s.push(a[]);
c[j++]=;
for(int i=;i<n;i++)
{
if(s.empty())
{
s.push(a[num+]);
num++;
c[j++]=;
}
while(s.top()!=b[i]&&num<n-)
{
s.push(a[num+]);
num++;
c[j++]=;
}
if(s.top()==b[i])
{
c[j++]=-;
s.pop();
} }
if(s.empty())
{
cout<<"Yes."<<endl;
for(int i=;i<j;i++)
{
if(c[i]==)
cout<<"in"<<endl;
if(c[i]==-)
cout<<"out"<<endl;
}
}
else
cout<<"No."<<endl;
cout<<"FINISH"<<endl;
}
}
,按照这个顺序,如果栈顶的符合,则出栈,如果不符合,继续进栈,直到找到符合的(应注意的是,时刻保持栈内有元素,否则访问栈顶的时候会出现,访问越界的错误)
hdu1022 模拟栈的更多相关文章
- ACM/ICPC 之 用双向链表 or 模拟栈 解“栈混洗”问题-火车调度(TSH OJ - Train)
本篇用双向链表和模拟栈混洗过程两种解答方式具体解答“栈混洗”的应用问题 有关栈混洗的定义和解释在此篇:手记-栈与队列相关 列车调度(Train) 描述 某列车调度站的铁道联接结构如Figure 1所示 ...
- java 16 - 5 LinkedList模拟栈数据结构的集合
请用LinkedList模拟栈数据结构的集合,并测试 题目的意思是: 你自己的定义一个集合类,在这个集合类内部可以使用LinkedList模拟. package cn_LinkedList; impo ...
- hdu 4699 Editor 模拟栈
思路:刚开始用STL中的栈,一直RE……,之后改为手动模拟栈操作,在注意点细节就可以了!!! 代码如下: #include<cstdio> #include<cstring> ...
- 【DataStructure In Python】Python模拟栈和队列
用Python模拟栈和队列主要是利用List,当然也可以使用collection的deque.以下内容为栈: #! /usr/bin/env python # DataStructure Stack ...
- 第一回写的用arraylist模拟栈操作
package hashMap; import java.util.ArrayList; import d.Student; /** * 用ArrayList模拟栈操作 * @author zhuji ...
- HDOJ/HDU 1022 Train Problem I(模拟栈)
Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot o ...
- c语言学习,模拟栈操作
1.stack.c模拟栈操作函数的实现 #include<stdio.h> #include<stdlib.h> ; static char *stack;//数据栈 ;//栈 ...
- KEILC51可重入函数及模拟栈浅析
MARK:文章中的红色部分是个人的理解. KEILC51可重入函数及模拟栈浅析 关键字:keilc51,模拟堆栈,可重入函数调用,参数传递,C?XBP,C?ADDXBP 摘要:本文较详细的介绍了kei ...
- 使用golang的slice来模拟栈
slice(切片):底层数据结构是数组 stack(栈):一种先进后出的数据结构 普通版的模拟写入和读取的栈 package main import "fmt" //栈的特点是先进 ...
随机推荐
- hdu 4286 (list的reverse时间复杂度为n)
list 的翻转reverse源码: // 将链表倒置 // 其算法核心是历遍链表, 每次取出一个结点, 并插入到链表起始点 // 历遍完成后链表满足倒置 template <class T, ...
- C# static 字段初始值设定项无法引用非静态字段、方法或属性
问题:字段或属性的问题字段初始值设定项无法引用非静态字段.方法 下面代码出错的原因,在类中定义的字段为什么不能用? public string text = test(); //提示 字段或属性的问题 ...
- .netcore部署到IIS上出现HTTP Error 502.5 - Process Failure问题解决
首先网上是有很多解决方案,但是对我这个错误完全没用 如果你们没有环境首先得预装环境如下 1.首先在bing.com下搜索asp.net core download, 然后打开搜索到的信息.NET Do ...
- ping包,支持ip录入
@echo off ::等待用户输入需要监控IP set /p ip=Input the IP required to monitor: echo executing...... :start ech ...
- 如何将Sql server数据库中的模型图转化到Word中--并能够查看字段的属性信息
1. 在Sql server数据库中创建数据库的模型图 -- Database Diagrams 2. 控制面板--管理工具--ODBC数据源链接--创建一个Sql server的数据源链接 3. 打 ...
- dubbo 安装部署Windows
1 安装zookeeper 2 安装dubbo 1 下载源码 https://github.com/alibaba/dubbo 2 编译 mvn clean package install -D ...
- <select>标签默认值设置
<td> <label>操作类型:</label> <select id="operation_type" class="com ...
- mysql 复制(主从复制)
一.概述 让一台服务器的数据与其他服务器数据保持同步.一台主库的数据可以同步到多台备库上,而备库本身也可以配置成其他服务器的主库. 主要应用: 1) 数据分布 2) 负载均衡 3) 伪备份.在备份基础 ...
- [Algorithm]查找
一.查找的算法 1.顺序查找 1 int Search_Seq( SeqList L, ElemType elem ) 2 { 3 L.elem[0] = elem; 4 for ( int i = ...
- javascript前端导出csv表格
使用场景 后台统计经常要展示各种各样的表格数据,几乎每个表格展示都会伴随着数据的导出. 之前的解决方案都是通过发起一个相同查询参数(querystring)的导出请求(action=export),由 ...