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 ...
随机推荐
- opencv6.3-imgproc图像处理模块之边缘检测
接opencv6.2-improc图像处理模块之图像尺寸上的操作 本文大部分都是来自于转http://www.opencv.org.cn/opencvdoc/2.3.2/html/doc/tutori ...
- 浅谈Javascript 中几种克隆(clone)方式
clone就是把原来的东西原样复制一份,新复制的东西和以前的东西没有任何关系 一:在Javascript里,如果克隆对象是基本类型,我们直接赋值就可以了: var sStr = "kingw ...
- 使用ContentProvider进行应用程序间的数据交互
什么是ContentProvider: ContentProvider用来管理数据的访问规则.它允许你的应用程序向外界暴露需要被访问的数据. 是Android的四大组件之一. ContentProvi ...
- Using LINQ to SharePoint
LINQ and LINQ Providers LINQ is a feature of the programming languages C# and Microsoft Visual Bas ...
- mailto: HTML e-mail 链接
转载: http://www.haorooms.com/post/mailto_link_html 什么是mailto链接? mailto链接是一种html链接,能够设置你电脑中邮件的默认发送信息.但 ...
- Tomcat5通过cardadm.xml启动项目
配置tomcat5\conf\Catalina\localhost下的 cardadm.xml ,然后在MyEclipse中,直接启动Tomcat5,不需要部署项目
- iOS开发小技巧--iOS中设置applicationIconBadgeNumber遇到的问题
iOS中设置applicationIconBadgeNumber 在iOS7中直接设置applicationIconBadgeNumber没有问题,但是在iOS8之后设置applicationIcon ...
- Mac 下,配置SVN
Mac 环境下 sv 服务器的配置 本文目录 • 一.创建代码仓库,用来存储客户端所上传的代码 • 二.配置svn的用户权限 • 三.使用svn客户端功能 在Windows环境中,我们一般使用Tort ...
- Sublime Text插件:HTML+CSS+JAVASCRIPT+JSON快速格式化[转]
今天在github上乱逛,无意间找到victorporof分享的htmlpretty插件,特做推荐: 先看看他是怎么描述htmlpretty的: This is a Sublime Text 2 an ...
- 100200H
这是个bfs 首先建图,先从终点bfs求出每点距离,然后从起点开始,确定初始方向:某点和自己相邻距离比自己小1就是 然后就先贪心和上次一样的方向,如果不能走,就找出一个方向,把自己当前方向改掉,重复过 ...