水一发,主要是要判断一下queue和stack是不是空的,不是空的再执行pop操作,虽然想到了但是没改,RE了一下才写。
/*
* @Author: SamsonHo
* @Date: 2019-02-23-00.15
* @URL:https://vjudge.net/problem/UVA-11995
* @Note:
*/
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int MAXN = 1e5+10;
string str_ans[] = {"stack","queue","priority queue","impossible","not sure"};
int main(void)
{
//ios::sync_with_stdio(false);
int n;
while(cin>>n)
{
stack<int> s;
queue<int> que;
priority_queue<int> pque;
int typ,num;
int ans[5] = {1,1,1,1};
for(int i = 0; i < n; ++i)
{
cin>>typ>>num;
if(typ == 1)
{
que.push(num);
pque.push(num);
s.push(num);
}
else if(typ == 2)
{
if(ans[0] && !s.empty() && s.top() == num)
s.pop();
else
ans[0] = 0;
if(ans[1] && !que.empty() && que.front() == num)
que.pop();
else
ans[1] = 0;
if(ans[2] && !pque.empty() && pque.top() == num)
pque.pop();
else
ans[2] = 0;
}
}
num = ans[0]+ans[1]+ans[2];
if(num == 1)
{
for(int i = 0; i < 3; ++i)
{
if(ans[i])
{
cout<<str_ans[i]<<'\n';
break;
}
}
}
else if(num > 1)
cout<<"not sure\n";
else if(num == 0)
cout<<"impossible\n";
}
}