Problem I

I Can Guess the Data Structure!

There is a bag-like data structure, supporting two operations:

  1. 1 x

Throw an element x into the bag.

  1. 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:

  1. stack

It's definitely a stack.

  1. queue

It's definitely a queue.

  1. priority queue

It's definitely a priority queue.

  1. impossible

It can't be a stack, a queue or a priority queue.

  1. not sure

It can be more than one of the three data structures mentioned above.

Sample Input

  1. 6
  2. 1 1
  3. 1 2
  4. 1 3
  5. 2 1
  6. 2 2
  7. 2 3
  8. 6
  9. 1 1
  10. 1 2
  11. 1 3
  12. 2 3
  13. 2 2
  14. 2 1
  15. 2
  16. 1 1
  17. 2 2
  18. 4
  19. 1 2
  20. 1 1
  21. 2 1
  22. 2 2
  23. 7
  24. 1 2
  25. 1 5
  26. 1 1
  27. 1 3
  28. 2 5
  29. 1 4
  30. 2 4

Output for the Sample Input

  1. queue
  2. not sure
  3. impossible
  4. stack
  5. priority queue
  6.  
  7. 题目大意:根据数据的操作<1>插入<2>删除判别是哪一种数据类型,有栈、队列、优先队列几种类型,如三种
    都不符合输出impossbile,符合两种以上输出not sure,只符合一种的对应输出它的类型名称。
  1. #include <iostream>
  2. #include <queue>
  3. #include <stack>
  4. #include <cstdio>
  5. #define Max 1010
  6. using namespace std;
  7.  
  8. int N;
  9. int op[Max],num[Max];
  10. stack<int> S;
  11. queue<int> Q;
  12. priority_queue<int> PQ;
  13. int check_stack()
  14. {
  15. int i,t;
  16. while(!S.empty()) S.pop();
  17. for(i=;i<N;i++)
  18. {
  19. if(op[i]==)
  20. {
  21. if(S.empty()) return ;
  22. t=S.top();S.pop();
  23. if(t!=num[i]) return ;
  24. }
  25. else S.push(num[i]);
  26. }
  27. return ;
  28. }
  29. int check_queue()
  30. {
  31. int i,t;
  32. while(!Q.empty()) Q.pop();
  33. for(i=;i<N;i++)
  34. {
  35. if(op[i]==)
  36. {
  37. if(Q.empty()) return ;
  38. t=Q.front();Q.pop();
  39. if(t!=num[i]) return ;
  40. }
  41. else Q.push(num[i]);
  42. }
  43. return ;
  44. }
  45. int check_priorityqueue()
  46. {
  47. int i,t;
  48. while(!PQ.empty()) PQ.pop();
  49. for(i=;i<N;i++)
  50. {
  51. if(op[i]==)
  52. {
  53. if(PQ.empty()) return ;
  54. t=PQ.top();PQ.pop();
  55. if(t!=num[i]) return ;
  56. }
  57. else PQ.push(num[i]);
  58. }
  59. return ;
  60. }
  61. int main()
  62. {
  63. int i;
  64. int s,q,pq;
  65. while(scanf("%d",&N)!=EOF)
  66. {
  67. for(i=;i<N;i++) scanf("%d %d",op+i,num+i);
  68. s=check_stack();
  69. q=check_queue();
  70. pq=check_priorityqueue();
  71. if(!s && !q && !pq) printf("impossible\n");
  72. else if(s && !q && !pq) printf("stack\n");
  73. else if(!s && q && !pq) printf("queue\n");
  74. else if(!s && !q && pq) printf("priority queue\n");
  75. else printf("not sure\n");
  76. }
  77. return ;
  78. }
  1.  

uva 11995 判别数据类型的更多相关文章

  1. [UVA] 11995 - I Can Guess the Data Structure! [STL应用]

    11995 - I Can Guess the Data Structure! Time limit: 1.000 seconds Problem I I Can Guess the Data Str ...

  2. STL UVA 11995 I Can Guess the Data Structure!

    题目传送门 题意:训练指南P186 分析:主要为了熟悉STL中的stack,queue,priority_queue,尤其是优先队列从小到大的写法 #include <bits/stdc++.h ...

  3. UVa 11995:I Can Guess the Data Structure!(数据结构练习)

    I Can Guess the Data Structure! There is a bag-like data structure, supporting two operations: 1 x T ...

  4. UVa 11995 I Can Guess the Data Structure!

    做道水题凑凑题量,=_=||. 直接用STL里的queue.stack 和 priority_queue模拟就好了,看看取出的元素是否和输入中的相等,注意在此之前要判断一下是否非空. #include ...

  5. uva 11995 I Can Guess the Data Structure stack,queue,priority_queue

    题意:给你n个操做,判断是那种数据结构. #include<iostream> #include<cstdio> #include<cstdlib> #includ ...

  6. UVA 11995 I Can Guess the Data Structure!(ADT)

    I Can Guess the Data Structure! There is a bag-like data structure, supporting two operations: 1 x T ...

  7. UVA - 11995 I Can Guess the Data Structure!(模拟)

    思路:分别定义栈,队列,优先队列(数值大的优先级越高).每次放入的时候,就往分别向三个数据结构中加入这个数:每次取出的时候就检查这个数是否与三个数据结构的第一个数(栈顶,队首),不相等就排除这个数据结 ...

  8. UVA - 11995 - I Can Guess the Data Structure! STL 模拟

    There is a bag-like data structure, supporting two operations: 1 x Throw an element x into the bag. ...

  9. UVA - 11995 模拟

    #include<iostream> #include<cstdio> #include<algorithm> #include<cstdlib> #i ...

随机推荐

  1. es的插件 ik分词器的安装和使用

    今天折腾了一天,在es 5.5.0 上安装ik.一直通过官方给定的命令没用安装成功,决定通过手工是形式进行安装.https://github.com/medcl/elasticsearch-analy ...

  2. 文字自动自左向右滚动的js代码

    重要的一点,就是scrollLeft一直在变化.对象一直在移动,参照物没有动. 代码: css: #div1{display:black;width:110px;height:50px;line-he ...

  3. (六)使用Docker镜像(下)

    1. 创建镜像 创建镜像的方法有三种: 基于已有镜像的容器创建 基于本地模板导入 基于Dockerfile创建 1.1 基于已有镜像的容器创建 该方法主要是使用docker commit命令,其格式 ...

  4. 各种分布(distribution)

    正态分布(Normal distribution),又名高斯分布(Gaussian distribution).若随机变量X服从一个数学期望为μ.方差为σ^2(标准差为σ)的正态分布,记为N(μ,σ^ ...

  5. 实 Jordan 标准型和实 Weyr 标准型

    将学习到什么 本节讨论关于实矩阵的实形式的 Jordan 标准型,也讨论关于复矩阵的另外一种形式的 Jordan 标准型,因为它在与交换性有关的问题中很有用.   实 Jordan 标准型 假设 \( ...

  6. OpenCascade:屏闪问题。

    1.在OnDraw中同时调用用V3d_View::Redaw()和 V3d_View::FitAll();可暂时解决. 2.在OnDraw中同时调用用V3d_View::Update();

  7. 自己开发一个APP需要多少钱

    广州APP开发公司[启汇网络]经常遇到有开发定制APP软件需求的企业,通常第一句问的就是“开发一款APP需要多少钱”,在做完客户行业的市场调查后,再了解客... 广州APP开发公司[启汇网络]经常遇到 ...

  8. null 理解

    值 null 特指对象的值未设置.它是 JavaScript 基本类型 之一. 语法节 null 描述节 值 null 是一个字面量,它不像undefined 是全局对象的一个属性.null 是表示缺 ...

  9. servlet多文件上传(带进度条)

    需要commons-fileupload-1.3.jar和commons-io-2.4.jar的支持 页面效果:(图片文件都可以) (1)进度标识类 public class UploadStatus ...

  10. MySQL插入SQL语句后在phpmyadmin中注释显示乱码

    自己写一个建一个简单的数据表,中间加了个注释,但是用PHPmyadmin打开后发现注释不对. 就先查询了一下sql 语句 发现SQL 语句并没有问题,感觉像是显示编码的问题,就先用set names ...