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 ...
随机推荐
- 【python游戏编程之旅】第八篇---pygame游戏开发常用数据结构
本系列博客介绍以python+pygame库进行小游戏的开发.有写的不对之处还望各位海涵. 上一个博客我们一起学习了pygame中冲突检测技术:http://www.cnblogs.com/msxh/ ...
- [POJ1284]Primitive Roots(原根性质的应用)
题目:http://poj.org/problem?id=1284 题意:就是求一个奇素数有多少个原根 分析: 使得方程a^x=1(mod m)成立的最小正整数x是φ(m),则称a是m的一个原根 然后 ...
- android SwipeRefreshLayout google官方下拉刷新控件
下拉刷新功能之前一直使用的是XlistView很方便我前面的博客有介绍 SwipeRefreshLayout是google官方推出的下拉刷新控件使用方法也比较简单 今天就来使用下SwipeRefres ...
- [转]servlet中的service, doGet, doPost方法的区别和联系
原文地址:http://m.blog.csdn.net/blog/ghyg525/22928567 大家都知道在javax.servlet.Servlet接口中只有init, service, des ...
- iOS开发小技巧--即时通讯项目:消息发送框(UITextView)高度的变化; 以及UITextView光标复位的小技巧
1.即时通讯项目中输入框(UITextView)跟随输入文字的增多,高度变化的实现 最主要的方法就是监听UITextView的文字变化的方法- (void)textViewDidChange:(UIT ...
- 强连通 HDU 1269
n点m边 求是否能从任意a->b b->a 强连通分量等于1 #include<stdio.h> #include<algorithm> #include<s ...
- poj2553 强连通缩点
The Bottom of a Graph Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 10114 Accepted: ...
- DOS命令行下mysql 基本命令
第一招.mysql服务的启动和停止 net stop mysql net start mysql 第二招.登陆mysql 语法如下: mysql -u用户名 -p用户密码 键入命令mysql -uro ...
- Web前端性能优化教程01:减少Http请求
性能黄金法则 只有10%-20%的最终用户响应时间花在接收请求的HTML文档上,剩下的80%-90%时间花在HTML文档所引用的所有组件(图片,script,css,flash等等)进行的HTTP请求 ...
- 回合对战制游戏第一篇(初识java)
回合对战制游戏第一篇 一,所谓的java. java是一门完全面向对象的编程语言,而之前所接触到的C语言是一门面向有一个过程的语音,对于两个的区别应该有一个清楚的认识. java的第一个内容. 类和对 ...