题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1022

题目大意:

车的进出站问题,先给出N个火车,再按序列一的方式进站,判断能否以序列二的方式出站,若能先输出“Yes.”,再输出出站步骤,以FINISH结束,若不能,输出“No.”,仍以FINISH结束。

思路:

直接模拟栈,注意细节!

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + ;
const int INF = << ;
int T, n, m;
int v[];
int main()
{
string s1, s2;
while(cin >> n >> s1 >> s2)
{
int j = ;
int tot = , ok = ;
stack<char>q;
for(int i = ; i < s1.size(); i++)
{
q.push(s1[i]);
v[tot++] = ;
while(!q.empty() && q.top() == s2[j])//一开始将j++写在这里,是错的,因为每次判断条件都会加一
{
q.pop();
v[tot++] = ;
j++;
}
}
if(j == n && tot == * n)printf("Yes.\n");
else printf("No.\n");
if(j == n && tot == * n)
{
for(int i = ; i < tot; i++)if(v[i])printf("in\n");
else printf("out\n");
}
printf("FINISH\n");
}
return ;
}

hdu1022 Train Problem I---模拟栈的更多相关文章

  1. HDOJ/HDU 1022 Train Problem I(模拟栈)

    Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot o ...

  2. HDU 1022 Train Problem I 模拟栈题解

    火车进站,模拟一个栈的操作,额外的栈操作,查看能否依照规定顺序出栈. 数据量非常少,故此题目非常easyAC. 直接使用数组模拟就好. #include <stdio.h> const i ...

  3. hdu 1022 Train Problem I(栈的应用+STL)

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  4. Train Problem I--hdu1022(栈)

    Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  5. 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 ...

  6. HDU 1022 Train Problem I(栈的操作规则)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1022 Train Problem I Time Limit: 2000/1000 MS (Java/Ot ...

  7. HDU1022 Train Problem I 栈的模拟

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1042 栈的模拟,题目大意是已知元素次序, 判断出栈次序是否合理. 需要考虑到各种情况, 分类处理. 常 ...

  8. HDU 1022 Train Problem I(栈模拟)

    传送门 Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of st ...

  9. HDU Train Problem I 1022 栈模拟

    题目大意: 给你一个n 代表有n列 火车,  第一个给你的一个字符串 代表即将进入到轨道上火车的编号顺序, 第二个字符串代表的是 火车出来之后到顺序, 分析一下就知道这,这个问题就是栈, 先进后出吗, ...

随机推荐

  1. 2017/11/25 2D变换

    2D变换 一.盒模型解析模式 1.box-sizing:盒模型解析模式 1)content-box:标准盒模型(和css2一样的计算) 宽度和高度之外绘制元素的内边距和边框 width,height外 ...

  2. angularjs上传图片和文件

    很简单: $scope.upload = function() { var f = $scope.myFile; var fd = new FormData(); var img = document ...

  3. Spring容器中Bean的生命周期

  4. Maven-10: 使用maven-help-plugin描述插件

    除了访问在线的插件文档之外,还可以借助maven-help-plugin来获取插件的详细信息.可以运行如下命令来获取maven-compiler-plugin2.1版本的信息: [INFO] Scan ...

  5. Gitlab - Pull Request

    1.概述 今天查看Gmail,有网友私密我Gitlab的Pull Request工作流程,一直以为我写过这片博客,查看<Git和Gitlab协同工作>却发现遗漏了Pull Request这 ...

  6. 网络通信 --> select()用法

    select()用法 头文件 #include <sys/time.h> #include <sys/types.h> #include <unistd.h> 定义 ...

  7. 定位bug的姿势对吗?

    举个例子来说明 WEB页面上数据显示错误,本来应该显示38,  结果显示35,这个时候你怎么去定位这个问题出在哪里? 1.通过fiddler抓包工具(或者其他抓包工具), 分析接口返回的数据是35还是 ...

  8. css3 背景色 实现边框渐变运动动画

    css3 #body_id { animation: myfirst 10s ease-in-out -2s infinite alternate; /* Firefox: */ -moz-anima ...

  9. java多线程的(一)-之java线程的使用

    一.摘要 每天都和电脑打交道,也相信大家使用过资源管理器杀掉过进程.而windows本身就是多进程的操作系统 在这里我们理解两组基本概念: 1.进程和线程的区别???? 2.并行与并发的区别???? ...

  10. 网络1711班 C语言第七次作业批改总结

    网络1711班 C语言第七次作业批改总结 1.本次作业评分细则 1.1 基本要求(1分) 按时交 - 有分 未交 - 0分 迟交一周以上 - 倒扣本次作业分数 抄袭 - 0分 泛泛而谈(最多七分) 1 ...