uva 11995 - I Can Guess the Data Structure!
来源:互联网 发布:淘宝客服不回话怎么办 编辑:程序博客网 时间:2024/06/04 17:52
大致题意:输入1表示push,2表示pop,输出:
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!
- Uva-11995-I Can Guess the Data Structure!
- Uva 11995 - I Can Guess the Data Structure!
- 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!
- uva 11995 - I Can Guess the Data Structure!
- Uva 11995 - I Can Guess the Data Structure! (判断数据类型)
- 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 I Can Guess the Data Structure!
- 11995 - I Can Guess the Data Structure! uva
- UVA 573 The Snail
- ubuntu下ADB not respondingc错误处理
- OnCtlColor
- 手机不能访问webservice的问题解决
- 策略模式
- uva 11995 - I Can Guess the Data Structure!
- 康托展开
- 练习一下用Java处理大数
- JAVA的类访问修饰符
- 快速排序
- Opencv-2.0.0的ARM移植和使用(Ubuntu10.04 / OK6410开发板 / linux3.01)
- 让VC调试器正确显示UTF-8字符串
- sicily 1206.Stacking Cylinders
- sendfile为什么比read、writer快