UVA - 11995 I Can Guess the Data Structure!(水题)

解析:

水题,定义三种数据结构然后后模拟其情况,然后判断就可以了。

AC代码

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int N = 1005;
int ele[N],oper[N];
int n;

int main() {
    bool ans[3];
    while(scanf("%d", &n) != EOF) {
        memset(ans, true, sizeof(ans));
        priority_queue<int> pri_que;
        queue<int> que;
        stack<int> st;
        for(int i = 0; i < n; i++) {
            scanf("%d%d", &oper[i], &ele[i]);
            if(oper[i] == 1) {
                pri_que.push(ele[i]);
                que.push(ele[i]);
                st.push(ele[i]);
            }else {
                if(st.empty() || ele[i] != st.top()) 
                    ans[0] = false;
                else st.pop();

                if(que.empty() || ele[i] != que.front())
                    ans[1] = false;
                else que.pop();

                if(pri_que.empty() || ele[i] != pri_que.top())
                    ans[2] = false;
                else pri_que.pop();
            }
        }
        int cnt = 0;
        for(int i = 0; i < 3; i++) {
            if(ans[i]) cnt++;
        }
        if(cnt == 0)
            puts("impossible");
        else if(cnt >= 2) 
            puts("not sure");
        else if(ans[0]) 
            puts("stack");
        else if(ans[1]) 
            puts("queue");
        else if(ans[2])
            puts("priority queue");
    }
    return 0;
}

你可能感兴趣的:(uva,11995)