Uva 11995 I Can Guess the Data Structure!
Uva 11995 I Can Guess the Data Structure!
思路:队列,栈和优先队列的模拟。用STL更方便。
代码:
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back #define mem(a,b) memset(a,b,sizeof(a)) int main() { ios::sync_with_stdio(false); cin.tie(0); int n,u,v; while(cin>>n) { queue<int>q; stack<int>s; priority_queue<int>pq; bool flag0=true,flag1=true,flag2=true; for(int i=0;i<n;i++) { cin>>u>>v; if(u==1) { q.push(v); s.push(v); pq.push(v); } else if(u==2) { if(q.empty()||s.empty()||pq.empty())//防止越界 { flag0=flag1=flag2=false; continue; } if(v!=q.front())flag0=false; if(v!=s.top())flag1=false; if(v!=pq.top())flag2=false; q.pop(); s.pop(); pq.pop(); } } if(flag0&&(!flag1)&&(!flag2))cout<<"queue"<<endl; else if((!flag0)&&flag1&&(!flag2))cout<<"stack"<<endl; else if((!flag0)&&(!flag1)&&flag2)cout<<"priority queue"<<endl; else if((!flag0)&&(!flag1)&&(!flag2))cout<<"impossible"<<endl; else cout<<"not sure"<<endl; } return 0; }