http://acm.split.hdu.edu.cn/showproblem.php?pid=1022

题意:给出火车的进站与出站顺序,判断是否可以按照给出的出站顺序出站。

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <math.h> using namespace std; #define INF 0x3f3f3f3f
const int maxn = ;
typedef long long LL; int main()
{
int n;
int a[];
char str1[], str2[]; while(scanf("%d%s%s", &n, str1, str2)!=EOF)
{
stack<char>Q;
Q.push(str1[]); memset(a, , sizeof(a));
a[] = ; int i=;
int j=;
int k=; while(i<n && j<n)
{
if(Q.size() && Q.top()==str2[j])
{
a[++k]=;
Q.pop();
j++;
}
else
{
Q.push(str1[++i]);
a[++k]=;
}
} if(k!=*n) printf("No.\n");
else
{
printf("Yes.\n"); for(int i=;i<=k;i++)
if(a[i])
printf("in\n");
else
printf("out\n"); }
printf("FINISH\n");
}
return ;
}

Train Problem I hdu 1022(栈)的更多相关文章

  1. HDU - 1022 Train Problem I STL 压栈

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

  2. Train Problem II HDU 1023 卡特兰数

    Problem Description As we all know the Train Problem I, the boss of the Ignatius Train Station want ...

  3. HDU 1022 Train Problem I (数据结构 —— 栈)

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

  4. HDU Train Problem I (STL_栈)

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

  5. Train Problem I (HDU 100题纪念)

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...

  6. Train Problem I(模拟栈)

    题意:模拟栈,试问使用2个栈,能否使得串1变为串2 思路:模拟,经典问题,注意只要相同的元素放到栈顶后就不会再移动了,只需要考虑剩下的元素,因此每次只考虑一个元素的进入方式. #include< ...

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

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

  8. hdu 1022 Train Problem I【模拟出入栈】

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

  9. Hdu 1022 Train Problem I 栈

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

随机推荐

  1. ASP.NET MVC Web API 学习笔记---第一个Web API程序

    http://www.cnblogs.com/qingyuan/archive/2012/10/12/2720824.html GetListAll /api/Contact GetListBySex ...

  2. php二维数组排序方法(转自http://www.3lian.com/edu/2013/12-26/118882.html)

    一维数组排序可以使用asort.ksort等一些方法进程排序,相对来说比较简单.二维数组的排序怎么实现呢?使用array_multisort和usort可以实现 例如像下面的数组:    代码如下: ...

  3. “请运行Chkdsk工具”怎么解决

    今天重新系统,想从移动硬盘中拷贝数据,但是老是提示:“请运行Chkdsk工具” 于是在百度搜索一下,有人提供的解决方案很不错,在些引用一下,以备忘! 电脑上经常遇到这样的提示“某某某文件已损坏且无法读 ...

  4. (LinkedList) Remove Linked List Elements

    Remove all elements from a linked list of integers that have value val. ExampleGiven: 1 --> 2 --& ...

  5. ztree

    http://www.s u c h s o.com/projecteactual/ztree-jiaocheng-mvc-checkbox-quanxuan-demo-down.html http: ...

  6. C#EXCEL 操作类--C#DataToExcel帮助类

    using System; using System.Diagnostics; //using Excel; namespace DotNet.Utilities {     /// <summ ...

  7. 学习了一下javascript的模块化编程

    现在在我脑海里关于“模块化”的概念是这些词:简单.具有逻辑之美.易用.健壮.可扩展.似乎这些形容与我现在水平写出的代码有点格格不入啊. 所以今天想了解和简单的实践一下“模块化开发”. 1.首先学习一下 ...

  8. 埃及分数-IDA*

    Description 在古埃及,人们使用单位分数的和(形如1/a的, a是自然数)表示一切有理数.如:2/3=1/2+1/6,但不允许2/3=1/3+1/3,因为加数中有相同的.对于一个分数a/b, ...

  9. assembly打包。

    --排除 <?xml version="1.0" encoding="UTF-8"?><assembly    xmlns="htt ...

  10. Libevent 定时器

    先摘一点网上的介绍 libevent是一个事件触发的网络库,适用于windows.linux.bsd等多种平台,内部使用select.epoll.kqueue等系统调用管理事件机制.著名分布式缓存软件 ...