UVA - 11995 I Can Guess the Data Structure!

题意:求满足操作的数据结构

思路:模拟

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;

int n,o,e,cs,s,q,pq;

int main(){
    while (scanf("%d",&n) != EOF){
        stack<int > st;
        queue<int > qu;
        priority_queue<int > pqu;
        s = q = pq = 1;
        while (n--){
            scanf("%d %d",&o,&e);
            if (o == 1){
                st.push(e);
                qu.push(e);
                pqu.push(e);
            }
            else if (o == 2){
                if (!st.empty()){
                    if (st.top() != e)
                        s = 0;
                    st.pop();
                }
                else s = 0;
                if (!qu.empty()){
                    if (qu.front() != e)
                        q = 0;
                    qu.pop();
                }
                else q = 0;
                if (!pqu.empty()){
                    if (pqu.top() != e)
                        pq = 0;
                    pqu.pop();
                }
                else pq = 0;
            }
        }
        if (s && !q && !pq)
            printf("stack\n");
        else if (!s && q && !pq)
            printf("queue\n");
        else if (!s && !q && pq)
            printf("priority queue\n");
        else if (!s && !q && !pq)
            printf("impossible\n");
        else printf("not sure\n");
    }
    return 0;
}



你可能感兴趣的:(UVA - 11995 I Can Guess the Data Structure!)