码迷,mamicode.com
首页 > 其他好文 > 详细

Uva 11995 I Can Guess the Data Structure!

时间:2017-10-04 19:35:48      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:name   span   not   lan   tar   越界   ++   eof   return   

Uva 11995 I Can Guess the Data Structure!

思路:队列,栈和优先队列的模拟。用STL更方便。

代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,u,v;
    while(cin>>n)
    {
        queue<int>q;
        stack<int>s;
        priority_queue<int>pq;
        bool flag0=true,flag1=true,flag2=true;
        for(int i=0;i<n;i++)
        {
            cin>>u>>v;
            if(u==1)
            {
                q.push(v);
                s.push(v);
                pq.push(v);
            }
            else if(u==2)
            {
                if(q.empty()||s.empty()||pq.empty())//防止越界 
                {
                    flag0=flag1=flag2=false;
                    continue;
                 } 
                if(v!=q.front())flag0=false;
                if(v!=s.top())flag1=false;
                if(v!=pq.top())flag2=false; 
                q.pop();
                s.pop();
                pq.pop(); 
            }
        }
        if(flag0&&(!flag1)&&(!flag2))cout<<"queue"<<endl;
        else if((!flag0)&&flag1&&(!flag2))cout<<"stack"<<endl;
        else if((!flag0)&&(!flag1)&&flag2)cout<<"priority queue"<<endl;
        else if((!flag0)&&(!flag1)&&(!flag2))cout<<"impossible"<<endl;
        else cout<<"not sure"<<endl;
    }
    return 0;
}

 

Uva 11995 I Can Guess the Data Structure!

标签:name   span   not   lan   tar   越界   ++   eof   return   

原文地址:http://www.cnblogs.com/widsom/p/7627001.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!