做道水题凑凑题量,=_=||。

直接用STL里的queue、stack 和 priority_queue模拟就好了,看看取出的元素是否和输入中的相等,注意在此之前要判断一下是否非空。

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. void scan( int &x )
  5. {
  6. char c;
  7. while( c = getchar(), c < '' || c > '' );
  8. x = c - '';
  9. while( c = getchar(), c >= '' && c <= '' ) x = x* + c - '';
  10. }
  11.  
  12. const int maxn = + ;
  13. int t[maxn], d[maxn];
  14.  
  15. bool is_queue(int n)
  16. {
  17. queue<int> Q;
  18. for(int i = ; i < n; i++)
  19. {
  20. if(t[i] == ) Q.push(d[i]);
  21. else
  22. {
  23. if(Q.empty()) return false;
  24. int x = Q.front(); Q.pop();
  25. if(x != d[i]) return false;
  26. }
  27. }
  28. return true;
  29. }
  30.  
  31. bool is_stack(int n)
  32. {
  33. stack<int> S;
  34. for(int i = ; i < n; i++)
  35. {
  36. if(t[i] == ) S.push(d[i]);
  37. else
  38. {
  39. if(S.empty()) return false;
  40. int x = S.top(); S.pop();
  41. if(x != d[i]) return false;
  42. }
  43. }
  44. return true;
  45. }
  46.  
  47. bool is_p_queue(int n)
  48. {
  49. priority_queue<int> Q;
  50. for(int i = ; i < n; i++)
  51. {
  52. if(t[i] == ) Q.push(d[i]);
  53. else
  54. {
  55. if(Q.empty()) return false;
  56. int x = Q.top(); Q.pop();
  57. if(x != d[i]) return false;
  58. }
  59. }
  60. return true;
  61. }
  62.  
  63. int main()
  64. {
  65. //freopen("in.txt", "r", stdin);
  66.  
  67. int n;
  68. while(scanf("%d", &n) == )
  69. {
  70. for(int i = ; i < n; i++) { scan(t[i]); scan(d[i]); }
  71. bool f1 = is_queue(n);
  72. bool f2 = is_stack(n);
  73. bool f3 = is_p_queue(n);
  74. int cnt = (int)f1 + (int)f2 + (int)f3;
  75. if(cnt > ) puts("not sure");
  76. else if(cnt == ) puts("impossible");
  77. else
  78. {
  79. if(f1) puts("queue");
  80. if(f2) puts("stack");
  81. if(f3) puts("priority queue");
  82. }
  83. }
  84.  
  85. return ;
  86. }

代码君

UVa 11995 I Can Guess the Data Structure!的更多相关文章

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

  3. 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 ...

  4. 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. ...

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

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

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

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

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

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

  8. uva-11995 - I Can Guess the Data Structure!(栈,优先队列,队列,水题)

    11995 - I Can Guess the Data Structure! There is a bag-like data structure, supporting two operation ...

  9. [LeetCode] All O`one Data Structure 全O(1)的数据结构

    Implement a data structure supporting the following operations: Inc(Key) - Inserts a new key with va ...

随机推荐

  1. ssh连接慢

    suse刚装完,开始用ssh的时候,总会遇到这样的问题:输入了用户名以后,等半天才出输入密码的框,很是急人.这是dns反查造成的.解决方法:编辑 /etc/ssh/sshd_conf , 将 #Use ...

  2. 原码 & 反码 & 补码 & 详解

    本篇文章讲解了计算机的原码, 反码和补码. 并且进行了深入探求了为何要使用反码和补码, 以及更进一步的论证了为何可以用反码, 补码的加法计算原码的减法. 论证部分如有不对的地方请各位牛人帮忙指正! 希 ...

  3. win8 ubuntu

    点进去看到几点注意: 1. 如果Windows是UEFI方式安装的,那Ubuntu必须也用UEFI方式安装 2. 必须用64位的Ubuntu安装文件,32位的不能探测EFI 3. 必须用UEFI的方式 ...

  4. 如何监控业务的响应速度?Cloud Insight SDK 实践分享

    一直在说 Cloud Insight 是数据聚合平台,可以用 SDK 和 API 实现业务监控,如今不拿出点实践人们恐怕是不能信服.那今天本文就先简单介绍一下 SDK 可以应用在哪些方面,再举个真实用 ...

  5. js正则函数match、exec、test、search、replace、split使用介绍

    match() 使用正则表达式模式对字符串执行查找,并将包含查找的结果作为数组返回. stringObj.match(rgExp) stringObj 必选项.对其进行查找的 String 对象或字符 ...

  6. 李洪强iOS开发之【零基础学习iOS开发】【01-前言】01-开篇

    从今天开始,我就开始更新[零基础学习iOS开发]这个专题.不管你是否涉足过IT领域,也不管你是理科生还是文科生,只要你对iOS开发感兴趣,都可以来阅读此专题.我尽量以通俗易懂的语言,让每个人都能够看懂 ...

  7. python 解析 xml

    <taskList nextId="62292"> <task module="reliability" owner="vprovo ...

  8. javascript基础之数组对象

    一.定义数组的方法: 定义了一个空数组: var myArray =new Array(); 指定有n个空元素的数组: var myArray=new Array(n); 定义数组并赋值: var m ...

  9. 多线程进行n皇后计算

    在浏览zhihu的时候, 看到了这个问题:Linux c++服务器端这条线怎么走? http://www.zhihu.com/question/22608820 , 其中排第一的答案说的很不错.针对他 ...

  10. 243. Shortest Word Distance

    题目: Given a list of words and two words word1 and word2, return the shortest distance between these ...