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 ...
随机推荐
- Tomcat 启动提示未发现 APR 的解决方法
Tomcat 启动出现信息如下: 信息: The APR based Apache Tomcat Native library which allows optimal performance in ...
- Android反编译工具的使用-Android Killer
今天百度搜索“Android反编译”搜索出来的结果大多数都是比较传统的教程.刚接触反编译的时候,我也是从这些教程慢慢学起的.在后来的学习过程中,我接触到比较方便操作的Android反编译.在这,我将使 ...
- .Net分布式异常报警系统-服务端Service
服务端的2个Service 1. HandleService: 从Redis中获取异常信息, 入库并发送通知到相关责任人. 2. HealthyCheckService: 对站点指定页面进行模拟访问 ...
- SQL Server Data Tools – Business Intelligence for Visual Studio 2012安装时提示“The CPU architecture....”的解决方法
SQL Server Data Tools – Business Intelligence for Visual Studio 2012,一个很强大的工具,下载地址:http://www.micros ...
- Windows Phone 8 下载文件进度
后台代码: public partial class MainPage : PhoneApplicationPage { private long siz; private long speed; p ...
- [BZOJ2257][Jsoi2009]瓶子和燃料(数学)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=2257 分析: 1.先考虑确定的瓶子下的最小体积是多少 ①假设只有两个瓶子v1,v2,易 ...
- oracle从游标批量提取数据
来源于:http://blog.csdn.net/ceclar123/article/details/7974973 传统的fetch into一次只能取得一条数据,使用fetch bulk coll ...
- Qt学习中遇到的问题
问题: 一个Qt小项目,编译成功并成功运行,但应用程序输出中出现如下异常:FTH: (9892): *** Fault tolerant heap shim applied to current pr ...
- Question2Answer安装
Question2Answer安装 Question2Answer的安装过程很简单,只需要几分钟的时间你就可以有一个强大的问答系统. 安装要求 Web服务器(比如Apache) PHP 4.3 或更高 ...
- easyui-datagrid 的loader属性用法
API介绍比较简略: 定义如何从远程服务器加载数据.返回false可以放弃本次请求动作.该函数接受以下参数:param:参数对象传递给远程服务器.success(data):当检索数据成功的时候会调用 ...