当前位置: 代码迷 >> 综合 >> UVA 11995 I Can Guess the Data Structure! .
  详细解决方案

UVA 11995 I Can Guess the Data Structure! .

热度:86   发布时间:2023-09-23 04:29:19.0

题目地址:https://vjudge.net/problem/UVA-11995

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,b)  for(int i=a;i<=(int)(b);++i)
#define REPD(i,a,b) for(int i=a;i>=(int)(b);--i)
stack<int> s;
queue<int> q;
priority_queue<int> PQ;
int main(int argc, char const *argv[])
{int n;while(cin>>n){int c,x;bool st,qu,pq;while(!s.empty()) s.pop();while(!q.empty()) q.pop();while(!PQ.empty()) PQ.pop();st=qu=pq=true;REP(i,1,n) {cin>>c>>x;if(c==1) {s.push(x);q.push(x);PQ.push(x);}else {if(s.empty()||s.top()!=x) st=false;else s.pop();if(q.empty()||q.front()!=x) qu=false;else q.pop();if(PQ.empty()||PQ.top()!=x) pq=false;else PQ.pop();}}if(st+qu+pq==0) printf("impossible\n");else if(st+qu+pq>1) printf("not sure\n");else {if(st) printf("stack\n");if(qu) printf("queue\n");if(pq) printf("priority queue\n");}}return 0;
}


  相关解决方案