uva 11995 - I Can Guess the Data Structure!
2013-11-05 20:25
381 查看
大致题意:输入1表示push,2表示pop,输出:
stack:一定是个栈;
queue:一定是个队列;
priority:一定是个优先队列;
impossible:都不是;
not sure:至少有两种可能。
注意:它有可能在pop前已为空,所以要先判断empty()。
stack:一定是个栈;
queue:一定是个队列;
priority:一定是个优先队列;
impossible:都不是;
not sure:至少有两种可能。
注意:它有可能在pop前已为空,所以要先判断empty()。
#include<iostream> #include<cstdio> #include<queue> #include<stack> using namespace std; int main() { int i,n,t,x,f1,f2,f3,tmp; while(scanf("%d",&n)!=EOF) { queue<int>q; stack<int>s; priority_queue<int>r; f1=1,f2=1,f3=1; for(i=0;i<n;i++) { scanf("%d%d",&t,&x); if(t==1) { q.push(x); s.push(x); r.push(x); } else if(!q.empty()) { if(f1 && s.top()!=x) f1=0;s.pop(); if(f2 && q.front()!=x) f2=0;q.pop(); if(f3 && r.top()!=x) f3=0;r.pop(); } else f1=f2=f3=0; } tmp=f1+f2+f3; if(tmp==0) printf("impossible\n"); else if(tmp==1) { if(f1) printf("stack\n"); else if(f2) printf("queue\n"); else printf("priority queue\n"); } else printf("not sure\n"); } return 0; }
相关文章推荐
- [UVA] 11995 - I Can Guess the Data Structure! [STL应用]
- UVA 11995 - I Can Guess the Data Structure!
- UVA - 11995 - I Can Guess the Data Structure! STL 模拟
- uva 11995 - I Can Guess the Data Structure!
- UVA 11995:I Can Guess the Data Structure!(水)
- UVA - 11995 - I Can Guess the Data Structure! STL 模拟
- UVa 11995:I Can Guess the Data Structure!(数据结构练习)
- UVA 11995 - I Can Guess the Data Structure!【stl】
- Uva 11995 - I Can Guess the Data Structure!
- UVA 11995(p186)----I Can Guess the Data Structure!
- UVA 11995 - 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!
- 11995 - I Can Guess the Data Structure! uva
- uva - 11995 - I Can Guess the Data Structure!
- UVA - 11995 - I Can Guess the Data Structure! (基础数据结构练习!)
- UVa-11995 I Can Guess the Data Structure!(STL的使用)
- UVA - 11995 I Can Guess the Data Structure!
- uva11995 I Can Guess the Data Structure!(基本数据结构)