您的位置:首页 > 产品设计 > UI/UE

UVA - 11995 I Can Guess the Data Structure!

2014-02-16 20:45 567 查看
题意:求满足操作的数据结构

思路:模拟
#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: