阅读背景:

水题(I Can Guess the Data Structure!,UVA 11995)

来源:互联网 
#include<bits/stdc++.h>
using namespace std;

int n;
stack<int>s;
queue<int>q;
priority_queue<int>p;
bool a,b,c;


int main()
{
    while(~scanf("%d",&n))
    {
        while(!s.empty()) s.pop();
        while(!q.empty()) q.pop();
        while(!p.empty()) p.pop();
        a=b=c=true;
        int op,x;
        while(n--)
        {
            scanf("%d %d",&op,&x);
            if(op==1)
            {
                s.push(x);
                q.push(x);
                p.push(x);
            }
            else
            {
                if(a)
                {
                    if(s.empty()||s.top()!=x) a=false;
                    else s.pop();
                }
                if(b)
                {
                    if(q.empty()||q.front()!=x) b=false;
                    else q.pop();
                }
                if(c)
                {
                    if(p.empty()||p.top()!=x) c=false;
                    else p.pop();
                }
            }
        }
        if(!a&&!b&&!c) puts("impossible");
        else if(a&&!b&&!c) puts("stack");
        else if(!a&&b&&!c) puts("queue");
        else if(!a&&!b&&c) puts("priority queue");
        else puts("not sure");
    }
    return 0;
}
#include<bits/stdc++.h>
using namespace std;

i



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: