码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-02-18 00:56:30      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:

#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;
}

 

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

标签:

原文地址:http://www.cnblogs.com/sola1994/p/4295592.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!