# UVA 11995 - I Can Guess the Data Structure!【stl】

https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3146

#include<stdio.h>
#include<queue>
#include<stack>
using namespace std;
int main()
{
int n,m;
//	freopen("shuju.txt","r",stdin);
while(~scanf("%d",&n))
{
stack<int> s;
queue<int> q;
priority_queue<int> pq;
int cnt=0;
int kase[3]={0};// 0 栈，1 队列，2 优先队列
for(int i=0;i<n;++i)
{
int a,b;
scanf("%d%d",&a,&b);
if(a==1)
{
s.push(b);
q.push(b);
pq.push(b);
}
else
{
if(s.empty()||s.top()!=b)
{
kase[0]=1;
}
if(q.empty()||q.front()!=b)
{
kase[1]=1;
}
if(pq.empty()||pq.top()!=b)
{
kase[2]=1;
}
if(!s.empty())//好繁琐的三个判断
{
s.pop();
}
if(!q.empty())
{
q.pop();
}
if(!pq.empty())
{
pq.pop();
}
}
}
if(kase[0]&&kase[1]&&kase[2])
{
printf("impossible\n");
}
else if(!kase[0]&&kase[1]&&kase[2])
{
printf("stack\n");
}
else if(kase[0]&&!kase[1]&&kase[2])
{
printf("queue\n");
}
else if(kase[0]&&kase[1]&&!kase[2])
{
printf("priority queue\n");
}
else
{
printf("not sure\n");
}
}
return 0;
}

#### uva 11995 I Can Guess the Data Structure! （STL的简单应用）

2014-04-08 13:31:31

#### uva 11995 - I Can Guess the Data Structure!

2013-11-05 20:25:02

#### uva 11995 I Can Guess the Data Structure!

2014-06-19 22:57:14

#### UVa 11995 - I Can Guess the Data Structure!

2015-03-15 09:40:58

#### UVa:11995 I Can Guess the Data Structure!

2014-01-20 12:37:26

#### 11995 - I Can Guess the Data Structure! uva

2014-07-06 19:34:26

#### uva——11995——I Can Guess the Data Structure!

2014-02-15 23:18:08

#### （UVA - 11995）I Can Guess the Data Structure!

2017-08-27 10:40:12

#### uva 11995——I Can Guess the Data Structure!

2016-03-14 20:41:37

#### UVA - 11995 I Can Guess the Data Structure!

2014-02-16 20:45:53