首页 > 其他 > 详细

UVA - 11995 I Can Guess the Data Structure!

时间:2014-02-17 10:30:50      阅读:335      评论:0      收藏:0      [点我收藏+]

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

思路:模拟

#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!

原文:http://blog.csdn.net/u011345136/article/details/19296207

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!