UVA 11995 I Can Guess the Data Structure!<STL数据结构使用>
来源:互联网 发布:mac玩魔兽世界 编辑:程序博客网 时间:2024/06/11 07:40
I Can Guess the Data Structure!
There is a bag-like data structure, supporting two operations:
1 x
Throw an element x into the bag.
2
Take out an element from the bag.
Given a sequence of operations with return values, you're going to guess the data structure. It is a stack (Last-In, First-Out), a queue (First-In, First-Out), a priority-queue (Always take out larger elements first) or something else that you can hardly imagine!
Input
There are several test cases. Each test case begins with a line containing a single integer n (1<=n<=1000). Each of the next n lines is either a type-1 command, or an integer 2 followed by an integer x. That means after executing a type-2 command, we get an element x without error. The value of x is always a positive integer not larger than 100. The input is terminated by end-of-file (EOF). The size of input file does not exceed 1MB.
Output
For each test case, output one of the following:
stack
It's definitely a stack.
queue
It's definitely a queue.
priority queue
It's definitely a priority queue.
impossible
It can't be a stack, a queue or a priority queue.
not sure
It can be more than one of the three data structures mentioned above.
Sample Input
61 11 21 32 12 22 361 11 21 32 32 22 121 12 241 21 12 12 271 21 51 11 32 51 42 4
Output for the Sample Input
queuenot sureimpossiblestackpriority queue
题目很简单,判断给你的值能不能是所给的三个数据结构中的一种,如果有多种可能输出不确定,如果每一个都不可能输出impossible
有一点小坑,就是每次取得时候,还是要判断下是否为空.
#include<cstdio>#include<algorithm>#include<queue>#include<stack>using namespace std;int a[1005],b[1005];int main (){ int n; while(~scanf("%d",&n)){ int f1=1,f2=1,f3=1; stack<int>st; queue<int>qu; priority_queue<int>po_qu; for(int i=0;i<n;i++){ scanf("%d %d",&a[i],&b[i]); if(a[i]==1) { st.push(b[i]); qu.push(b[i]); po_qu.push(b[i]); } else { if(st.empty()) {f1=0;} if(qu.empty()) {f2=0;} if(po_qu.empty()){f3=0;} if((f1+f2+f3)==0) continue; else { if(st.top()==b[i]&&f1) st.pop(); else f1=0; if(qu.front()==b[i]&&f2) qu.pop(); else f2=0; if(po_qu.top()==b[i]&&f3) po_qu.pop(); else f3=0; } } } // printf("%d %d %d\n",f1,f2,f3); if((f1+f2+f3)>1) printf("not sure\n"); else if((f1+f2+f3)==0) printf("impossible\n"); else if(f1) printf("stack\n"); else if(f2) printf("queue\n"); else printf("priority queue\n"); } return 0;}
- UVA 11995 I Can Guess the Data Structure!<STL数据结构使用>
- uva 11995 I Can Guess the Data Structure!(STL)
- UVa 11995 I Can Guess the Data Structure! (STL)
- UVA 11995 I Can Guess the Data Structure!(STL应用)
- UVA - 11995 I Can Guess the Data Structure! STL模板
- 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! (数据结构) STL的应用
- UVA - 11995 I Can Guess the Data Structure! 猜猜数据结构(STL模拟)
- UVa-11995 I Can Guess the Data Structure!(STL的使用)
- UVA: I Can Guess the Data Structure!(stl模拟)
- uva 11995 I Can Guess the Data Structure! (STL的简单应用)
- UVA-11995 I Can Guess the Data Structure!(STL:各容器的简单运用)
- UVA 11995 I Can Guess the Data Structure! (STL的应用)
- uva 11995 - I Can Guess the Data Structure!(STL应用)
- AndroidStudio添加自动解析Json数据插件
- JAVA 多态、final关键字、抽象类和方法、 day10
- 单实例程序方法
- 基于cdh570的phoenix编译
- BootStrap简介及应用要点
- UVA 11995 I Can Guess the Data Structure!<STL数据结构使用>
- 自己搭建git服务器
- 如何比较PixelCNN与DCGAN两种Image generation方法?
- VS 编译出错
- weak alias
- 安卓自定义View进阶:Path之玩出花样(PathMeasure)
- 设计原则之迪米特原则
- mysql的缓冲查询和非缓冲查询
- 针对GZIP文件类型的并行读取