链接
https://vjudge.net/problem/UVA-11995
题解
做完这题我只想说STL大法好
就是我直接模拟三种数据结构,然后判断一下pop的时候pop出来的元素是不是和它的一样就行了
代码
#include <bits/stdc++.h>
#define maxn 1010
using namespace std;
int n;
int main()
{
int type, x, t1, t2, t3;
while(~scanf("%d",&n))
{
stack<int> s;
queue<int> q;
priority_queue<int> pq;
bitset<3> b;
b.set();
while(n--)
{
scanf("%d%d",&type,&x);
if(type==1)
{
s.emplace(x);
q.emplace(x);
pq.emplace(x);
}
else
{
t1 = t2 = t3 = -1;
if(!s.empty())t1=s.top(), s.pop();
if(!q.empty())t2=q.front(), q.pop();
if(!pq.empty())t3=pq.top(), pq.pop();
if(t1!=x)b.reset(0);
if(t2!=x)b.reset(1);
if(t3!=x)b.reset(2);
}
}
if(b.count()==0)
{
printf("impossible\n");
}
else if(b.count()==1)
{
if(b.test(0))
{
printf("stack\n");
}
if(b.test(1))
{
printf("queue\n");
}
if(b.test(2))
{
printf("priority queue\n");
}
}
else
{
printf("not sure\n");
}
}
return 0;
}