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 ...
随机推荐
- PhoneGap奇怪的现象:File FileTransfer download, 手机相册检测不到下载下来的图片(解决)
我有个从服务器下载相片的功能在使用 File FileTransfer download api时,碰到了很奇怪的现象:图片已经从服务器里下载了,手机文件夹里也可以看到下载过来的图片,但是我的手机相册 ...
- lecture7-序列模型及递归神经网络RNN
Hinton 第七课 .这里先说下RNN有recurrent neural network 和 recursive neural network两种,是不一样的,前者指的是一种人工神经网络,后者指的是 ...
- 如何使用 UC浏览器开发者版 进行移动端调试
在 如何用 fiddler 代理调试本地手机页 一文中我们了解了如何用手机查看 PC 端写的网页(本地),但是我们只能看到页面效果,如果哪段 js 挂了,那部分样式失效了,我们该如何进行调试呢?今天为 ...
- stack overflow错误分析
stack overflow(堆栈溢出)就是不顾堆栈中分配的局部数据块大小,向该数据块写入了过多的数据,导致数据越界,结果覆盖了老的堆栈数据. 或者解释为 在长字符串中嵌入一段代码,并将过程的返回地址 ...
- j-link或者swd调试
两种 一.JTAG调试(5针), 二.SWD调试(2针), 在JTAG/SWD模式设置库函数 (在文件stm32f10x_gpio.c中): void GPIO_PinRemapConfig(uint ...
- 检测IE浏览器方法
var isIE=function(){ var b=document.createElement("b"); b.innerHTML="<!--[if IE]&g ...
- 42-stat 显示文件的信息
显示文件的信息 stat [options] [file-list] 参数 file-list指定stat所显示的一个或多个文件的路径名 选项 -f 显示文件系 ...
- ecshop 签名
先从index.php主页开始 页面关键字 {$keywords } 页面标题 {$page_title} 产品分类 父分类列表 {foreach from=$categories item=cat ...
- PHP 异常
<?php /* PHP 异常处理 什么是异常? PHP 5 提供了一种新的面向对象的错误处理方法. 异常处理用于在指定的错误(异常)情况发生时改变脚本的正常流程. 这种情况称为异常. 当异常被 ...
- 在无修改权限的情况下修改文件hosts中的内容
今天遇到了一个问题,本来希望修改hosts中的内容,但保存时被告知无权限,网上搜索有很多方法都无效,最后搜到一个简单的方法:将hosts文件复制到桌面上,修改,然后覆盖原来位置的hosts文件即可!