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

******************************************************************************************************************

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

6

1 1     1 2     1 3     2 1     2 2     2 3

6

1 1     1 2      1 3     2 3     2 2     2 1

2

1 1     2 2

4

1 2     1 1      2 1      2 2

7

1 2     1 5      1 1      1 3     2 5      1 4       2 4

******************************************************************************************************************

Sample Output

queue

not sure

impossible

stack

priority queue

******************************************************************************************************************

题意:根据操作,判断属于那种数据结构。

思路:使用STL中对应函数,进行模拟,若矛盾则不符合。

#include<stdio.h>
#include<queue>
#include<stack>
using namespace std;
int main()
{
int n;
while (~scanf("%d", &n))
{
stack<int>st;
queue<int>qu;
priority_queue<int>pr;
int a = 1, b = 1, c = 1;
for (int i = 0; i < n; i++)
{
int x, y;
scanf("%d %d", &x, &y);
if (x == 1)//向其中加入数据
{
st.push(y);
qu.push(y);
pr.push(y);
}
else
{
if (st.empty())
{
a = b = c = 0;
continue;
}
if (a)
a = (st.top() == y);//判断顶部的数是否与y相等
if (b)
b = (qu.front() == y);
if (c)
c = (pr.top() == y);
st.pop();
qu.pop();
pr.pop();
}
}
if (a + b + c > 1)
printf("not sure\n");
else if (a)
printf("stack\n");
else if (b)
printf("queue\n");
else if (c)
printf("priority queue\n");
else
printf("impossible\n");
} return 0;
}

UVA - 11995 - I Can Guess the Data Structure! STL 模拟的更多相关文章

  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!(模拟)

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

  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!(ADT)

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

  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!

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

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

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

  8. HDU 5929 Basic Data Structure 【模拟】 (2016CCPC东北地区大学生程序设计竞赛)

    Basic Data Structure Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  9. HDU 5929 Basic Data Structure(模拟 + 乱搞)题解

    题意:给定一种二进制操作nand,为 0 nand 0 = 10 nand 1 = 1 1 nand 0 = 1 1 nand 1 = 0 现在要你模拟一个队列,实现PUSH x 往队头塞入x,POP ...

随机推荐

  1. windows设置代理.bat 脚本

    按照下列脚本复制到记事本中,保存,重命名后缀为.bat,使用时双击即可. 设置代理.bat,修改下列脚本中的代理地址和端口号 @echo off echo 开始设置IE代理上网 reg add &qu ...

  2. CSS只改变背景透明度,不改变子元素透明度

    一般情况下,我们可以使用css的opcity属性改变某个元素的透明度,但是其元素下的子元素的透明度也会被改变,即使对子元素重新定义也没有用,例如: <div style="opacit ...

  3. [csp-201809-4]再卖菜 差分约束or记忆化搜索

    先更新第一个做法:差分约束 转化成最长路,求出的每一个解是满足差分方程的最小值 spfa求最短路 对于边(x->y) 有: if(dis[y] > dis[x] + a[i].d) dis ...

  4. 20155212 2016-2017-2《Java程序设计》课程总结

    每周博客 每周作业链接汇总 预备作业一:专业理解.未来展望.期望的师生关系. 预备作业二:HOMEWORK-2 预备作业三:HOMEWORK-3 第一周作业:学习教材Chapter 1 Java平台概 ...

  5. Python概念-禁锢术之__slots__

    之所以给它起名为禁锢术,并非空缺来风,下面我们来了解一下__slost__ __slost__:其实就是将类中的名称锁定,实例化对象,只可以赋值和调用,不可以删除名字和增加新的名字 代码示例:(实例化 ...

  6. 一个罕见的MSSQL注入漏洞案例

    一个罕见的MSSQL注入漏洞案例 这里作者准备分享一个在去年Google赏金计划中发现的相当罕见漏洞,也是作者在整个渗透测试生涯中唯一一次遇到的. 目标网站使用了微软 SQL Server 数据库并且 ...

  7. 使用隐藏form表单下载文件,解决url方式下载,由于环境问题而限制url长度,满足不了所有的需求!

    一 对于某些环境导出是直接用wiondow.href=url直接导出下载,有些业务需求,如员工档案等字段比较多的时候,全选导出就会引发异常,由于Nginx转发长度限制的问题, 如果运维不愿意改变环境, ...

  8. asp.net操作word 配置在IIS上出现的问题

    异常: 检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件失败,原因是出现以下错误: 80070005 拒绝访问. (异常来自 ...

  9. mac下---charles抓包https

    网上找的很多安装包都有问题,终于找到个可用的! 下载地址:  http://pan.baidu.com/s/1pLAONbX ———————————————————————————— 教程转载:htt ...

  10. conding.net或github,readme.md添加图片

    原因:    将图片放在仓库里面,在文件里链接它,最后 push 到 github 上.github 图片链接格式:(http://github.com/yourname/your-repositor ...