Uva 11995 I Can Guess the Data Structure!

Posted Wisdom+.+

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Uva 11995 I Can Guess the Data Structure!相关的知识,希望对你有一定的参考价值。

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!的主要内容,如果未能解决你的问题,请参考以下文章

uva 11995 I Can Guess the Data Structure!

UVA11995 I Can Guess the Data Structure!

UVa 11995 - I Can Guess the Data Structure!

UVA 1995 I can guess the structer

B - I Can Guess the Data Structure!(建议使用栈队列和优先队列来模拟)

UVA - 11995 模拟