uva11995 I Can Guess the Data Structure!(try to use simple structures)

题目意思:

给你一组操作,请根据操作的顺序,猜测这是何种数据结构。

https://vjudge.net/problem/UVA-11995


    #include<iostream>
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<math.h>
    #include<algorithm>
    #include<string>
    #include<stack>
    #include<queue>
    #include<map>
    #include<set>
    #include<vector>
    #define INF 0x7fffffff
    #define LL long long
    using namespace std;
    const int MAXN = 50005;
    int n;
    int main()
    {
        //重定向
        //freopen("E:/input.txt","r",stdin);
        //freopen("E:/output.txt","w",stdout);
        while(cin>>n){
            stack<int> sta;
            queue<int> que;
            priority_queue<int> pq;

            int op,x;
            int ok1,ok2,ok3;
            ok1 = ok2 = ok3 =1;
            for(int i=0;i<n;i++){
                cin>>op>>x;
                if(op == 1){
                    sta.push(x);
                    que.push(x);
                    pq.push(x);
                }
                if(op == 2){
                    if(!sta.empty()){
                        //cout<<sta.top()<<endl;
                        if(x != sta.top()){
                            ok1 = 0;
                        }
                        sta.pop();
                    }else{
                        ok1 = 0;
                    }

                    if(!que.empty()){
                        //cout<<que.front()<<endl;
                        if(x != que.front()){
                            ok2 = 0;
                        }
                        que.pop();
                    }else{
                        ok2 = 0;
                    }

                    if(!pq.empty()){
                        //cout<<pq.top()<<endl;
                        if(x != pq.top()){
                            ok3 = 0;
                        }
                        pq.pop();
                    }else{
                        ok3 = 0;
                    }
                }
            }
            if(ok1+ok2+ok3 >= 2){
                cout<<"not sure"<<endl;
            }
            else if(ok1+ok2+ok3 == 0){
                cout<<"impossible"<<endl;
            }
            else{
                if(ok1) cout<<"stack"<<endl;
                if(ok2) cout<<"queue"<<endl;
                if(ok3) cout<<"priority queue "<<endl;
            }
        }

        return 0;
    }


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值