[ create a new paste ] login | about

Link: http://codepad.org/OtbCb2aO    [ raw code | fork ]

iamyeasin - C++, pasted on Mar 21:
#include<bits/stdc++.h>
#define sf scanf
#define pf printf

using namespace std;


int main()
{
//    freopen("input.txt","rt",stdin);
//    freopen("output.txt","wt",stdout);

    stack < int > st;
    queue < int > q;
    priority_queue < int > pq;

    int s[42];
    int n[1050];
    int kase;

    while(sf("%d",&kase) != EOF)
    {
        int ss = 1,qq=1,ppqq = 1,nxt=0,flag =0,mm=0,ff=0,kk=0;
        s[0] = 0;
        s[1] = 0;
        s[2] = 0;

        for(int j=0; j<kase; j++)
        {
            int x,y;

            sf("%d %d",&x,&y);

            if(x&1)
            {
                st.push(y);
                q.push(y);
                pq.push(y);
            }
            else
            {
                if((st.top() != y) && !ff)
                {
                    s[0] = 1;
                    ff = 1;
                }

                if((q.front() != y) && !mm)
                {
                    s[1] = 1;
                    mm = 1;
                }

                if((pq.top() != y) && !kk)
                {
                    s[2] = 1;
                    kk=1;
                }

//                cout << " TOP VALUES OF STACK " << stk[nxt] << " " << st.top() << " " << n[nxt] << endl;
//                cout << " TOP VALUES OF Queue " << qu[nxt] << " " << q.front() << " " << n[nxt] << endl;
//                cout << " TOP VALUES OF PQueue " << pqu[nxt] << " " << pq.top() << " " << n[nxt] << endl;

                st.pop();
                q.pop();
                pq.pop();

                nxt++;
            }
        }

        if(!s[0] && (s[1] && s[2]))
        {
            pf("stack\n");
        }
        else if(!s[1] && (s[0] && s[2]))
        {
            pf("queue\n");
        }
        else if(!s[2] && (s[0] && s[1]))
        {
            pf("priority queue\n");
        }
        else if((!s[0] && !s[1]) || (!s[1] && !s[2]) || (!s[0] && !s[2]))
        {
            pf("not sure\n");
        }
        else if(s[0] && s[1] && s[2])
        {
            pf("impossible\n");
        }

        while(!q.empty() || !pq.empty() || !st.empty())
        {
            if(!q.empty())
            {
                q.pop();
            }
            if(!st.empty())
            {
                st.pop();
            }
            if(!pq.empty())
            {
                pq.pop();
            }
        }
    }


    return 0;
}


Create a new paste based on this one


Comments: