直接用栈、优先队列、队列来存取操作判断是否相符合就OK了
#include<cstdio>
#include<queue>
#include<stack>
#include<algorithm>
#include<iostream>
using namespace std;
int main(){
int n;
while(cin>>n){
priority_queue<int>q1;
queue<int>q2;
stack<int>s;
int casei,x;
int flag1 = 1,flag2 = 1,flag3 = 1;
while(n--){
cin>>casei>>x;
if(casei==1){
s.push(x);
q1.push(x);
q2.push(x);
}
else{
if(s.empty()){
flag1 = flag2 = flag3 = 0;
continue;
}
int d = s.top();
s.pop();
if(d != x)
flag1 = 0;
d = q1.top();
q1.pop();
if(d != x)
flag2 = 0;
d = q2.front();
q2.pop();
if(d != x)
flag3 = 0;
}
}
if(flag1+flag2+flag3 >= 2)
puts("not sure");
else if(flag1)
puts("stack");
else if(flag2)
puts("priority queue");
else if(flag3)
puts("queue");
else
puts("impossible");
}
return 0;
}