Thursday, June 9, 2016

uva 11995 solution

Unknown
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<stdlib.h>
using namespace std;

int main()
{
    int n;
    while (scanf("%d",&n)!=EOF)
    {
        stack<int>s;
        queue<int>q;
        priority_queue<int>pq;
        int stk=1,que=1,pque=1,a,b;
        while (n--)
        {
            scanf("%d%d",&a,&b);
            if (a==1)
            {
                if (stk) s.push(b);
                if (que) q.push(b);
                if (pque) pq.push(b);
            }
            else
            {
                if (stk)
                {
                    if (s.empty() || s.top()!=b) stk=0;
                    else s.pop();
                }
                if (que)
                {
                    if (q.empty() || q.front()!=b) que=0;
                    else q.pop();
                }
                if (pque)
                {
                    if (pq.empty() || pq.top()!=b) pque=0;
                    else pq.pop();
                }
            }
        }
        if (stk+que+pque==0) printf("impossible\n");
        else if (stk+que+pque==1)
        {
            if (stk) printf("stack\n");
            else if (que) printf("queue\n");
            else printf("priority queue\n");
        }
        else if (stk+que+pque>1) printf("not sure\n");
    }
    return 0;
}

Unknown

Studying at Shahjalal University of Science and Technology, Sylhet.

0 comments:

Post a Comment

Coprights @ 2016,