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 ...
随机推荐
- HDU2444-The Accomodation of Students-判断是否为二分图+ISAP
要先判断是不是二分图.用黑白染色法. 遇到已经染过的跟当前的颜色相同时就说明不是二分图,也即出现了奇环 /*---------------------------------------------- ...
- Qt中的qreal
在桌面操作系统中(比如Windows, XNix等)qreal其实就是double类型:而在嵌入设备系统中,qreal则等同于float 类型.
- WPF ListView和ListBox等双击事件问题
上两篇文章中说双击行获取不到当前数据对象问题, http://www.cnblogs.com/ligl/p/5636899.html http://www.cnblogs.com/ligl/p/562 ...
- Android实现滑动刻度尺效果,选择身高体重和生日
刻度尺效果虽然看起来很美,我个人认为很不实用,即使再不实用,也有用的,鉴于群里成员对我的苦苦哀求,我就分享一个他用不到的,横屏滑动刻度尺,因为他需要竖屏的,哈哈…… 最近群里的开发人员咨询怎样实现刻度 ...
- C#:异步编程和线程的使用(.NET 4.5 )
摘自:http://www.codeproject.com/Articles/996857/Asynchronous-programming-and-Threading-in-Csharp-N(葡萄城 ...
- The superclass javax.servlet.http.HttpServlet was not found on the Java Build Path。
项目上右键-->Build Path-->Configuration Build Path -->Add Library -->Server Runtime 选择tomcat
- cxf和spring结合,发布restFull风格的服务
rest(Representational State Transfer):表现层状态转化,它是一种风格,用于资源定位,例如:http://ip:port/user/student/001 和资源操作 ...
- Timer定时任务
// main方法 public static void main(String[] args) { timerEnter(); } // 设定指定任务task在指定延迟delay后进行固定延迟per ...
- 【UOJ #20】【NOIP 2014】解方程
http://uoj.ac/problem/20 并不会做...然后看题解....... 对a取模,避免了高精度带来的复杂度,然后再枚举x判断是否满足模意义下等于0. 取5个模数,我直接抄的别人的_( ...
- Entity Framework Code First (八)迁移 Migrations
创建初始模型和数据库 在开始使用迁移(Migrations)之前,我们需要一个 Project 和一个 Code First Model, 对于本文将使用典型的 Blog 和 Post 模型 创建一个 ...