思路
简单题,用栈,队列,优先队列直接模拟即可
代码
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <stack>
using namespace std;
queue<int> q;
stack<int> S;
priority_queue<int> pq;
int n;
int main(){
while(scanf("%d",&n)==1){
while(!q.empty())
q.pop();
while(!S.empty())
S.pop();
while(!pq.empty())
pq.pop();
bool isS=true,isq=true,ispq=true;
for(int i=1;i<=n;i++){
int opt,x;
scanf("%d %d",&opt,&x);
if(opt==1){
q.push(x);
pq.push(x);
S.push(x);
}
else{
if(q.empty())
isq=false;
if(pq.empty())
ispq=false;
if(S.empty())
isS=false;
if(isq){
int t=q.front();
if(t!=x)
isq=false;
q.pop();
}
if(ispq){
int t=pq.top();
if(t!=x)
ispq=false;
pq.pop();
}
if(isS){
int t=S.top();
if(t!=x)
isS=false;
S.pop();
}
}
}
if((!ispq)&&(!isq)&&(!isS))
printf("impossible
");
else if((ispq)&&(!isq)&&(!isS))
printf("priority queue
");
else if((!ispq)&&(isq)&&(!isS))
printf("queue
");
else if((!ispq)&&(!isq)&&(isS))
printf("stack
");
else
printf("not sure
");
}
return 0;
}