HDU Train Problem I 1022 栈模拟
题目大意:
给你一个n 代表有n列 火车, 第一个给你的一个字符串 代表即将进入到轨道上火车的编号顺序, 第二个字符串代表的是 火车出来之后到顺序,
分析一下就知道这,这个问题就是栈, 先进后出吗, 就是问你这个编号有没有可能出现, 有可能的话输出顺序,没可能直接输出No
题目分析:
我们用栈进行模拟, 先判断是否有这种出栈的可能, 假如有这种可能的话我们在模拟 一遍出栈的顺就行了。
每一次有新元素入栈我们就判断他是否雨 第二个字符串的第一个元素是否相等, 假如一样, 就让次元素出栈。
代码
#include <iostream>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <stack>
using namespace std;
#define maxn 15 bool OK(char str1[], char str2[],int n)//判断是否存在这种出栈的可能
{
stack<char> P;
P.push('#');//因为有元素要删除赋值, 不能为空, 我们让第一个元素为‘#’
char ans;
int i, j;
for(i=, j=; i<n; i++)
{
P.push(str1[i]);
ans = P.top();
while(ans == str2[j] )
{
P.pop();
j ++;
ans = P.top();//此处是要赋值判断的, 假如为空的话就无法赋值, 因此我们让第一个元素为‘#’
}
}
if(j == n)
return true;
return false;
} void Putt(char str1[], char str2[],int n)
{
stack<char> P;
P.push('#');
for(int i=, j=; i<n; i++)
{
P.push(str1[i]);
printf("in\n");
char ans = P.top();
while(ans == str2[j])
{
P.pop();
printf("out\n");
j ++;
ans = P.top();
}
}
}
int main()
{
int n;
char str1[maxn], str2[maxn];
while(cin >> n >> str1 >> str2)
{
if(OK(str1, str2, n) )
{
printf("Yes.\n");
Putt(str1,str2,n);
}
else
printf("No.\n"); printf("FINISH\n");
}
return ;
}
HDU Train Problem I 1022 栈模拟的更多相关文章
- HDU 1022 Train Problem I(栈模拟)
传送门 Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of st ...
- 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【栈的应用】【8月19】
Train Problem I Problem Description As the new term comes, the Ignatius Train Station is very busy n ...
- Train Problem I--hdu1022(栈)
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- hdu Train Problem I
这道题是道简单的栈模拟题,只要按照真实情况用栈进行模拟即可: #include<stdio.h> #include<string.h> #include<stack> ...
- hdu 1022 Train Problem I(栈)
#include<iostream> #include<vector> #include<cstring> #include<string> #incl ...
- HDU 1022 Train Problem I 用栈瞎搞
题目大意:有n辆火车,按一定的顺序进站(第一个字符串顺序),问是否能按规定的顺序出站(按第二个字符串的顺序出去),如果能输出每辆火车进出站的过程. 题目思路:栈的特点是先进后出,和题意类似,还有有一种 ...
- hdu Train Problem I(栈的简单应用)
Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot o ...
随机推荐
- poj 3154 Graveyard 贪心
//poj 3154 //sep9 #include <iostream> #include <cmath> using namespace std; double a[204 ...
- 深入分析 Java 中的中文编码问题--转
几种常见的编码格式 为什么要编码 不知道大家有没有想过一个问题,那就是为什么要编码?我们能不能不编码?要回答这个问题必须要回到计算机是如何表示我们人类能够理解的符号的,这些符号也就是我们人类使用的语言 ...
- MIUI6&7桌面角标开源代码简介
MIUI6&7桌面角标开源代码简介 MIUI6&7上重新设计了桌面app图标的角标显示,基本规则如下: 一.基本介绍 1.默认的情况 当app 向通知栏发送了一条通知 (通知不带进度条 ...
- CDOJ 92 – Journey 【LCA】
[题意]给出一棵树,有n个点(2≤N≤105),每条边有权值,现在打算新修一条路径,给出新路径u的起点v,终点和权值,下面给出Q(1≤Q≤105)个询问(a,b)问如果都按照最短路径走,从a到b节省了 ...
- .NET 拼音检索
微软提供了一个Visual Studio International Pack 组件,可以转换简繁体,或者将汉字转换为拼音以及其他语言的支持. https://www.microsoft.com/zh ...
- jQuery的live()方法对hover事件的处理示例
hover([over,]out) 一个模仿悬停事件(鼠标移动到一个对象上面及移出这个对象)的方法 当鼠标移动到一个匹配的元素上面时,会触发指定的第一个函数. 当鼠标移出这个元素时,会触发指定的第二个 ...
- asp.net使用dorpdownlist绑定无限级分类
/// <summary> /// 绑定父项分类 /// </summary> protected void DDLBindClass( ...
- 认识CSS样式
CSS全称为“层叠样式表 (Cascading Style Sheets)”,它主要是用于定义HTML内容在浏览器内的显示样式,如文字大小.颜色.字体加粗等. 如下列代码: p{ font-size: ...
- Ext Sencha Cmd 6 环境安装
Sencha Cmd安装笔记 在使用前端框架ExtJs前,需对其环境加以部署,对自己的安装过程加以记录. 建议大家在安装时,最好使用VPN,个中缘由,生在跳槽的程序袁应该都懂吧.不然ruby相关命令执 ...
- linux常用svn命令(转载)
原地址:http://www.rjgc.net/control/content/content.php?nid=4418 1.将文件checkout到本地目录svn checkout p ...