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

题目大意:

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

思路:

直接模拟栈,注意细节!

  1. #include<iostream>
  2. #include<cstdio>
  3. #include<cstring>
  4. #include<algorithm>
  5. #include<cmath>
  6. #include<queue>
  7. #include<stack>
  8. using namespace std;
  9. typedef long long ll;
  10. const int maxn = 1e6 + ;
  11. const int INF = << ;
  12. int T, n, m;
  13. int v[];
  14. int main()
  15. {
  16. string s1, s2;
  17. while(cin >> n >> s1 >> s2)
  18. {
  19. int j = ;
  20. int tot = , ok = ;
  21. stack<char>q;
  22. for(int i = ; i < s1.size(); i++)
  23. {
  24. q.push(s1[i]);
  25. v[tot++] = ;
  26. while(!q.empty() && q.top() == s2[j])//一开始将j++写在这里,是错的,因为每次判断条件都会加一
  27. {
  28. q.pop();
  29. v[tot++] = ;
  30. j++;
  31. }
  32. }
  33. if(j == n && tot == * n)printf("Yes.\n");
  34. else printf("No.\n");
  35. if(j == n && tot == * n)
  36. {
  37. for(int i = ; i < tot; i++)if(v[i])printf("in\n");
  38. else printf("out\n");
  39. }
  40. printf("FINISH\n");
  41. }
  42. return ;
  43. }

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. business expressions(一)

    一. 1.24/7 24/7 :twenty four hours a day, seven days a week I work 24/7.——meaing i work all the time. ...

  2. Redis进阶实践之十九 Redis如何使用lua脚本

    一.引言               redis学了一段时间了,基本的东西都没问题了.从今天开始讲写一些redis和lua脚本的相关的东西,lua这个脚本是一个好东西,可以运行在任何平台上,也可以嵌入 ...

  3. 【Python】excel读写操作 xlrd & xlwt

    xlrd ■ xlrd xlrd模块用于读取excel文件内容 基本用法: workbook = xlrd.open_workbook('文件路径') workbook.sheet_names() # ...

  4. 网络通信 --> Socket、TCP/IP、HTTP、FTP及网络编程

    Socket.TCP/IP.HTTP.FTP及网络编程 聊聊Socket.TCP/IP.HTTP.FTP及网络编程

  5. java中最常用jar包的用途说明

    java中最常用jar包的用途说明,适合初学者 jar包 用途 axis.jar SOAP引擎包 commons-discovery-0.2.jar 用来发现.查找和实现可插入式接口,提供一些一般类实 ...

  6. Java基础学习笔记二十五 MySQL

    MySQL 在dos中操作mysql 连接mysql命令: mysql -uroot -p密码 ,连接OK,会出现mysql> 对数据库的操作 创建一个库 create database 库名 ...

  7. 【MySql系列】MySql踩坑系列

    问题一:远程登录报错Host '192.168.181.201' is not allowed to connect to this MySQL server 解决: 问题二:MySql access ...

  8. Leetcode 24——Swap Nodes in Pairs

    Given a linked list, swap every two adjacent nodes and return its head. For example, Given 1->2-& ...

  9. 第二次作业评分可能要 delay 一些

    各位同学,因为我现在在出差,昨天刚刚到旧金山,加上倒时差,所以这次作业我处理得会更慢一些,希望谅解. 另外,博客园的邮件通知邮件好多都进垃圾箱了,所以如果你有什么问题我没回且你关心的,请给我写邮件:j ...

  10. C语言作业--数据类型

    一.PTA实验作业 题目1:7-7 发红包 1. 本题PTA提交列表 2. 设计思路 1定义整型变量hundred,fifty,twenty,ten,five,two,one分别存放不同金额的张数,n ...