UVA11995 I Can Guess the Data Structure!
Posted dreagonm
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了UVA11995 I Can Guess the Data Structure!相关的知识,希望对你有一定的参考价值。
思路
简单题,用栈,队列,优先队列直接模拟即可
代码
#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;
}
以上是关于UVA11995 I Can Guess the Data Structure!的主要内容,如果未能解决你的问题,请参考以下文章
uva 11995 I Can Guess the Data Structure!
UVA11995 I Can Guess the Data Structure!
UVa 11995 - I Can Guess the Data Structure!
UVA 1995 I can guess the structer