HDU 1702 ACboy needs your help again!

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

G++交,基本stl栈和队列操作

View Code
#include <iostream>
#include <stack>
#include <queue>
using namespace std ;
int main()
{
    int t ;
    scanf("%d",&t) ;
    while(t--)
    {
        int n,m ;
        string str ;
        cin >> n >> str ;
        if(str=="FIFO")
        {
            queue <int> q ;
            while(n--)
            {
                cin >> str ;
                if(str=="IN")
                {
                    cin >> m ;
                    q.push(m) ;
                }
                else
                {
                    if(q.empty())
                        puts("None") ;
                    else
                    {
                        printf("%d\n",q.front()) ;
                        q.pop() ;
                    }
                }
            }
            if(!q.empty())
                q.pop() ;
        }
        else
        {
            stack <int> s ;
            while(n--)
            {
                cin >> str ;
                if(str=="IN")
                {
                    cin >> m ; 
                    s.push(m) ;
                }
                else
                {
                    if(s.empty())
                        puts("None") ;
                    else
                    {
                        printf("%d\n",s.top()) ;
                        s.pop() ;
                    }
                }
            }
            if(!s.empty())
                s.pop() ;
        }
    }
    return 0 ;
}
原文地址:https://www.cnblogs.com/xiaohongmao/p/2611706.html