HDU 1022 Train Problem I 用栈瞎搞
题目大意:有n辆火车,按一定的顺序进站(第一个字符串顺序),问是否能按规定的顺序出站(按第二个字符串的顺序出去),如果能输出每辆火车进出站的过程。
题目思路:栈的特点是先进后出,和题意类似,还有有一种情况是:开进来立马有开出去。并用vis[]数组的0,1标记进出站情况。
具体看代码
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
#include<iostream>
#define MAX 100005
using namespace std; int main()
{
int A,B,top,i,j,n,vis[MAX],stack[MAX],ok;
char str1[MAX],str2[MAX];
while(scanf("%d%s%s",&n,str1,str2)!=EOF)
{
ok=;
memset(vis,,sizeof(vis));
i=;
A=;//当前str1的位置
B=;//当前str2的位置
top=;//栈顶
while(B<n)
{
if(str2[B]==str1[A])//如果两者相同就是即进即出的情况
{
vis[i++]=;//进站
vis[i++]=;//出站
A++;
B++;
} else if(top && stack[top]==str2[B])//如果栈非空,而且栈顶元素=str2当前元素则弹出栈
{
vis[i++]=;
top--;
B++;
} else if(A <= n)
{
stack[++top]=str1[A++];//压入栈
vis[i++]=;
} else
{
ok=;
break;
}
} if(!ok)
{
printf("No.\nFINISH\n");
} else
{
printf("Yes.\n");
for(j=;j<i;j++)
{
if(vis[j])
printf("in\n");
else
printf("out\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【栈的应用】【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(栈模拟)
传送门 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 1022 Train Problem I(栈)
#include<iostream> #include<vector> #include<cstring> #include<string> #incl ...
- HDU 1022 Train Problem I 模拟栈题解
火车进站,模拟一个栈的操作,额外的栈操作,查看能否依照规定顺序出栈. 数据量非常少,故此题目非常easyAC. 直接使用数组模拟就好. #include <stdio.h> const i ...
- 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) ...
随机推荐
- ActiveMQ in Action(2) - Transport
关键字: activemq 2.2 Transport ActiveMQ目前支持的transport有:VM Transport.TCP Transport.SSL Transport.Peer ...
- yum安装memcache,mongo扩展以及python的mysql模块安装
//启动memcached/usr/local/memcached/bin/memcached -d -c 10240 -m 1024 -p 11211 -u root/usr/local/memca ...
- jq选择器对象筛选
1.选择对象 1).基本 ·#id 根据给定的ID匹配一个元素.例如:$("#id")·element 根据给定的元素名匹配所有元素.例如:$("div")·. ...
- 【其他】MySql常用命令
Linux下: 登陆命令 mysql -h [hostname] -u [username] -p [password]修改密码 mysqladmin –u[username] –p[oldpwd] ...
- 2015 Multi-University Training Contest 10
1001 CRB and Apple 1002 CRB and Candies 1003 CRB and Farm 1004 CRB and Graph 1005 CRB and His Birthd ...
- eclipse和tomcat整合之后每次发布server.xml被修改(转)
eclipse每次发布,server.xml和context.xml总是被还原 直接找到eclispse工程下的server工程,把里面的相应的server.xml和context.xml修改了即可, ...
- hive深入
Hive QL: Create Table 创建一个指定名字的表.如果相同名字的表已经存在,则抛出异常:用户可以用 IF NOT EXIST 选项来忽略这个异常. EXTERNAL 关键字可以让用户创 ...
- Sqoop 将hdfs上的文件导入到oracle中,关于date类型的问题
近期的项目中,需要将hadoop运行完成的结果(存在于hdfs上)导入到oracle中,但是在用sqoop导入hdfs中的日期字段'2016-03-01'时,sqoop报错,说date类型必须为'yy ...
- ElasticSearch 的一次非正常master脱离的调查 (转 和我碰到的情况一模一样)
转自 http://simonlei.iteye.com/blog/1669992 一共有4个节点的cluster,其中es4 是master,某个时间突然es1脱离了整个cluster,调查过程如下 ...
- 拦截asp.net mvc输出流做处理, 拦截HTML文本(asp.net MVC版)
以前的一个贴子写过一个webForm的拦截HTML输出流的版本,最近用到mvc时用同样的方式发生一些问题. 如下图 查了好久也不知道啥原因. 好吧, 我最后选择放弃. 想起以前自定义Response. ...