题目意思:
给你一组操作,请根据操作的顺序,猜测这是何种数据结构。
https://vjudge.net/problem/UVA-11995
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<vector>
#define INF 0x7fffffff
#define LL long long
using namespace std;
const int MAXN = 50005;
int n;
int main()
{
//重定向
//freopen("E:/input.txt","r",stdin);
//freopen("E:/output.txt","w",stdout);
while(cin>>n){
stack<int> sta;
queue<int> que;
priority_queue<int> pq;
int op,x;
int ok1,ok2,ok3;
ok1 = ok2 = ok3 =1;
for(int i=0;i<n;i++){
cin>>op>>x;
if(op == 1){
sta.push(x);
que.push(x);
pq.push(x);
}
if(op == 2){
if(!sta.empty()){
//cout<<sta.top()<<endl;
if(x != sta.top()){
ok1 = 0;
}
sta.pop();
}else{
ok1 = 0;
}
if(!que.empty()){
//cout<<que.front()<<endl;
if(x != que.front()){
ok2 = 0;
}
que.pop();
}else{
ok2 = 0;
}
if(!pq.empty()){
//cout<<pq.top()<<endl;
if(x != pq.top()){
ok3 = 0;
}
pq.pop();
}else{
ok3 = 0;
}
}
}
if(ok1+ok2+ok3 >= 2){
cout<<"not sure"<<endl;
}
else if(ok1+ok2+ok3 == 0){
cout<<"impossible"<<endl;
}
else{
if(ok1) cout<<"stack"<<endl;
if(ok2) cout<<"queue"<<endl;
if(ok3) cout<<"priority queue "<<endl;
}
}
return 0;
}