HDU 1702 ACboy needs your help again!(栈 队列 基础)

#include<cstdio>
#include<cmath>
#include<queue>
#include<stack>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int t,n;
int main()
{
    int i,j,k;
    cin>>t;
    char op[10],io[10];
    while(t--)
    {
        scanf("%d%s",&n,op);
        if(op[2]==‘F‘)
        {
            queue<int> q;
            while(n--)
            {
                scanf("%s",io);
                if(io[0]==‘I‘)
                {
                    int temp;
                    scanf("%d",&temp);
                    q.push(temp);
                }
                else if(io[0]==‘O‘)
                {
                    if(q.empty())
                    {
                        printf("None\n");
                    }
                    else
                    {
                        int temp=q.front();
                        q.pop();
                        printf("%d\n",temp);
                    }
                }
            }
        }
        else if(op[2]==‘L‘)
        {
            stack<int> q;
            while(n--)
            {
                scanf("%s",io);
                if(io[0]==‘I‘)
                {
                    int temp;
                    scanf("%d",&temp);
                    q.push(temp);
                }
                else if(io[0]==‘O‘)
                {
                    if(q.empty())
                    {
                        printf("None\n");
                    }
                    else
                    {
                        int temp=q.top();
                        q.pop();
                        printf("%d\n",temp);
                    }
                }
            }
        }
    }

    return 0;
}
时间: 2024-08-07 22:03:32

HDU 1702 ACboy needs your help again!(栈 队列 基础)的相关文章

HDU 1702 ACboy needs your help again! (栈和队列的模拟)

ACboy needs your help again! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3164    Accepted Submission(s): 1655 Problem Description ACboy was kidnapped!! he miss his mother very much and is ve

HDU 1702 ACboy needs your help again! (栈与队列)

ACboy needs your help again! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3701    Accepted Submission(s): 1885 Problem Description ACboy was kidnapped!! he miss his mother very much and is v

hdu 1702 ACboy needs your help again!

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1702 题目大意:按照所给要求,输出相应的数.“FIFO”指代先进先出,即队列的概念,“FILO”指代先进后出,即栈的表现形式~这里定义两个函数即可,一个队列,一个栈的调用! 1 #include <iostream> 2 #include <cstdio> 3 #include <queue> 4 #include <stack> 5 #include <

HDU - 1702 ACboy needs your help again!(栈和队列)

Description ACboy was kidnapped!! he miss his mother very much and is very scare now.You can't image how dark the room he was put into is, so poor :(. As a smart ACMer, you want to get ACboy out of the monster's labyrinth.But when you arrive at the g

HDU 1702 ACboy needs your help again!(附加优先队列)

ACboy was kidnapped!! he miss his mother very much and is very scare now.You can't image how dark the room he was put into is, so poor :(.As a smart ACMer, you want to get ACboy out of the monster's labyrinth.But when you arrive at the gate of the ma

HDOJ 1702 ACboy needs your help again!

题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1702 ACboy needs your help again! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3512    Accepted Submission(s): 1797 Problem Description ACboy w

hdu 1712 ACboy needs your help

转载请注明出处:http://blog.csdn.net/u012860063 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1712 Problem Description ACboy has N courses this term, and he plans to spend at most M days on study.Of course,the profit he will gain from different course depen

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

HDU 1712 ACboy needs your help(DP)

Problem Description ACboy has N courses this term, and he plans to spend at most M days on study.Of course,the profit he will gain from different course depending on the days he spend on it.How to arrange the M days for the N courses to maximize the