Train Problem I hdu 1022(栈)

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 = 600;
typedef long long LL;

int main()
{
    int n;
    int result[100];
    char str1[100], str2[100];

    while(scanf("%d%s%s", &n, str1, str2)!=EOF)
    {
        memset(result, 0, sizeof(result));

        stack<char>Q;
        Q.push(str1[0]);
        result[0] = 1;

        int i=0;
        int j=0;
        int k=1;

        while(i<n && j<n)
        {
            if(Q.size() && Q.top()==str2[j])
            {
                j++;
                Q.pop();
                result[k++]=0;
            }
            else
            {
                if(i==n) break;
                Q.push(str1[++i]);
                result[k++]=1;
            }
        }

        if(i==n) printf("No.\n");
        else
        {
            printf("Yes.\n");

            for(int i=0;i<k;i++)
                if(result[i])
                printf("in\n");
            else
                printf("out\n");

        }
        printf("FINISH\n");
    }
    return 0;
}

/*
1 1 1
*/

时间: 2024-08-03 01:00:39

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

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

Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is the fastest all over the world ^v^). But here comes

hdoj 1022 Train Problem I 【顺序栈】

最近打算重新看一边数据结构,昨天看的时候感觉栈这部分部分能看懂了. 于是就赶紧来实践一下!! Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 19493    Accepted Submission(s): 7305 Problem Description As the new term comes, t

Train Problem II HDU 1023 卡特兰数

Problem Description As we all know the Train Problem I, the boss of the Ignatius Train Station want to know if all the trains come in strict-increasing order, how many orders that all the trains can get out of the railway. Input The input contains se

HDU Train Problem I (STL_栈)

Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is the fastest all over the world ^v^). But here comes

hdu1022(Train Problem I)----- 典型栈类题目

点击打开链接 Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays. A lot of student want to get back to school by train(because the trains in the Ignatius Train Station is the fastest all over the world ^v^). But here

HDU 1022 Train Problem I 模拟栈题解

火车进站,模拟一个栈的操作,额外的栈操作,查看是否能按照规定顺序出栈. 数据量很少,故此题目很容易AC. 直接使用数组模拟就好. #include <stdio.h> const int MAX_N = 10; char inOrder[MAX_N], outOrder[MAX_N], stk[MAX_N]; bool rs[MAX_N<<2]; int n; int main() { while (scanf("%d", &n) != EOF) { s

HDU 1022 Train Problem I (STL 栈模拟)

Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 30420    Accepted Submission(s): 11492 Problem Description As the new term comes, the Ignatius Train Station is very busy nowaday

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

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1022 Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 45375    Accepted Submission(s): 16966 Problem Description As the new term come

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

Train Problem I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 20521    Accepted Submission(s): 7712 Problem Description As the new term comes, the Ignatius Train Station is very busy nowadays