About Me

About Me : I have been working as a Software Engineer for various international companies for four years.Currently, I am working as a full stack Javascript developer in Petronas(Malaysia).

Skills

Skills • Javascript •Typescript •Python •C •Java •ReactJs • Redux • VueJs • NestJs • React Testing Library • Django• PostgreSQL • MySQL • NodeJs • Git • Docker • Jira • Visual Studio Code • Slack

রবিবার, ৩০ আগস্ট, ২০১৫

UVA :11995 - I Can Guess the Data Structure!

#include <bits/stdc++.h>
#define READ freopen ("input.txt","r",stdin)
#define nnn 20

using namespace std;

typedef long long ll;
typedef vector < int > vi;

int main()
{
    //READ;
    int n;
    stack<int>st;
    queue<int>Q;
    priority_queue<int>pq;
    while(~scanf("%d",&n))
    {
        while(!st.empty())st.pop();
        while(!Q.empty()) Q.pop();
        while(!pq.empty())pq.pop();
        bool stk=true;
        bool que=true;
        bool pque=true;
        bool ccc=true;
        for(int k=0; k<n; k++)
        {
            int op,value;
            scanf("%d %d",&op,&value);
            if(op==1)
            {
                st.push(value);
                Q.push(value);
                pq.push(value);
            }
            else
            {
                if(st.size()==0||Q.size()==0||pq.size()==0)
                {
                    ccc=false;
                    continue;
                }
                if(st.top()!=value) stk=false;
                else st.pop();
                if(Q.front()!=value) que=false;
                else Q.pop();
                if(pq.top()!=value) pque=false;
                else pq.pop();

            }

        }
        if(ccc==false )
        {
            puts("impossible");
            continue;
        }
        if(stk==false&&que==false&&pque==false) puts("impossible");
        else if(stk==true&&que==false&&pque==false) puts("stack");
        else  if(stk==false&&que==true&&pque==false) puts("queue");
        else  if(stk==false&&que==false&&pque==true) puts("priority queue");
        else puts("not sure");

    }


    return 0;
}

কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন