HDU 1022 Train Problem I(栈模拟)
Description



Input
Output
Sample Input
- 3 123 321 3 123 312
Sample Output
- Yes.in in in out out out FINISH No. FINISH
思路
- #include<iostream>
- #include<cstdio>
- #include<stack>
- using namespace std;
- const int maxn = 15;
- int main()
- {
- int N;
- while (~scanf("%d",&N))
- {
- bool flag = true;
- stack<int>stk;
- int i,inout[maxn] = {0},in[maxn],out[maxn];
- char sin[maxn],sout[maxn];
- scanf("%s %s",sin,sout);
- for (i = 0;i < N;i++) in[i] = sin[i] - '0';
- for (i = 0;i < N;i++) out[i] = sout[i] - '0';
- // for (i = 0;i < N;i++) printf("%d %d\n",in[i],out[i]);
- int j = 0,p = 0;
- i = 0;
- for (i = 0;i < N;i++)
- {
- if (in[i] != out[j])
- {
- inout[p++] = 0;
- stk.push(in[i]);
- }
- else if (in[i] == out[j])
- {
- inout[p++] = 0;
- j++;
- inout[p++] = 1;
- while (!stk.empty() && stk.top() == out[j])
- {
- j++;
- inout[p++] = 1;
- stk.pop();
- }
- }
- }
- while (!stk.empty())
- {
- if (stk.top() != out[j])
- {
- flag = false;
- break;
- }
- else
- {
- j++;
- stk.pop();
- inout[p++] = 1;
- }
- }
- if (!flag) printf("No.\nFINISH\n");
- else
- {
- printf("Yes.\n");
- for (i = 0;i < p;i++) inout[i]?printf("out\n"):printf("in\n");
- printf("FINISH\n");
- }
- }
- return 0;
- }
- /*
- 5
- 12342 24321
- */
HDU 1022 Train Problem 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) ...
- 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 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【栈的应用】【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(数据结构,栈,递归,dfs)
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 ...
- HDU 1022 Train Problem I
A - Train Problem I Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
随机推荐
- Oracle 数据库日常巡检
1. 检查数据库基本状况 包含:检查Oracle实例状态,检查Oracle服务进程,检查Oracle监听进程,共三个部分. 1.1. 检查Oracle实例状态 select instance_name ...
- .Net 异步方法加上“timeout”
在本羊读大学的时候,Thread让本羊云里雾里,代码写的痛不欲生,真的是让本羊脑袋里很多“线”缠绕在一起. 之后,Task让本羊代码写的飞起,甚至有时候根本不需要Task的时候还是要写上,那样显得档次 ...
- HBase配置项详解
hbase.tmp.dir:本地文件系统的临时目录,默认是java.io.tmpdir/hbase−java.io.tmpdir/hbase−{user.name}: hbase.rootdir:hb ...
- ASP.NET - SqlSugar ORM框架 更新列表
以后SqlSugar所有更新都会在这个贴子更新 SqlSugar是一款轻量级的MSSQL ORM ,除了具有媲美ADO的性能外还具有和EF相似简单易用的语法. 学习列表 0.功能更新 1.SqlSug ...
- 使用axes函数在matlab绘图中实现图中图的绘制
使用axes函数在matlab绘图中实现图中图的绘制 有时为了对细节进行详细说明,需要在一个较大坐标轴上绘制一个小图来对局部进行放大以阐述结果. 这可以通过调用axes函数实现. 下面通过绘制 y=1 ...
- jaccard similarity coefficient 相似度计算
Jaccard index From Wikipedia, the free encyclopedia The Jaccard index, also known as the Jaccard ...
- RabbitMQ官方中文入门教程(PHP版) 第四部分:路由(Routing)
路由(Routing) 在前面的教程中,我们实现了一个简单的日志系统.可以把日志消息广播给多个接收者. 本篇教程中我们打算新增一个功能——使得它能够只订阅消息的一个字集.例如,我们只需要把严重的错误日 ...
- 软件工程(FZU2015)学生博客列表(最终版)
FZU:福州大学软件工程 张老师的博客:http://www.cnblogs.com/easteast/ 经过前两周选课,最后正式选上课程的所有学生博客如下: 序号 学号后3位 博客 1 629 li ...
- springMvc接受日期类型参数处理
这个问题,也即是springMvc如何进行参数类型的转换 以把client传过来一个String类型,转换为日期类型为例: 1.controller /** * 接收日期类型参数 * 注意: * sp ...
- truncate与delete的区别
TRUNCATE TABLE 在功能上与不带 WHERE 子句的 DELETE 语句相同:二者均删除表中的全部行.但 TRUNCATE TABLE 比 DELETE 速度快,且使用的系统和事务日志资源 ...