大意:猜数据结构是栈、队列或者优先队列,可能为两种以上,也可能都不是。

水题。。

STL 记得判断是否为空

#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
using namespace std;
const int MAXN=1000+24;
int num[MAXN],action[MAXN],n;
bool check_stack()
{
stack<int> a;
for(int i=0;i<n;i++)
{
if(action[i]==1)
a.push(num[i]);
else
{
if(a.empty()) return false;
if(num[i]!=a.top()) return false;
a.pop();
}
}
return true;
} bool check_queue()
{
queue <int >a;
for(int i=0;i<n;i++)
{
if(action[i]==1)
a.push(num[i]);
else
{
if(a.empty()) return false;
if(num[i]!=a.front()) return false;
a.pop();
}
}
return true;
} bool check_pq() //check priority queue
{
priority_queue <int >a;
for(int i=0;i<n;i++)
{
if(action[i]==1)
a.push(num[i]);
else
{
if(a.empty()) return false;
if(num[i]!=a.top()) return false;
a.pop();
}
}
return true;
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
bool s,q,p;
for(int i=0;i<n;i++)
scanf("%d%d",&action[i],&num[i]);
s=q=p=0;
s=check_stack();
q=check_queue();
p=check_pq();
if(s && !q && !p) printf("stack\n");
else if(!s && q && !p) printf("queue\n");
else if(!s && !q && p) printf("priority queue\n");
else if (s ||q ||p) printf("not sure\n");
else printf("impossible\n");
}
}

11995 - I Can Guess the Data的更多相关文章

  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!

    做道水题凑凑题量,=_=||. 直接用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. UVA - 11995 I Can Guess the Data Structure!(模拟)

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

  9. Trainning Guide, Data Structures, Example

    最近在复习数据结构,发现这套题不错,题目质量好,覆盖广,Data Structures部分包括Example,以及简单,中等,难三个部分,这几天把Example的做完了, 摘要如下: 通过这几题让我复 ...

随机推荐

  1. Image-Loader LruMemoryCache

    这段时间在研究Universal-Image-Loader 这个图片处理开源框架,这里主要分析一下它的LRU(Least Resently Used,最近最少使用算法)内存缓存的实现. 在UIL它提供 ...

  2. js---12对象创建方式,构造器,原型

    <script type="text/javascript"> var o = {}; var o1 = new Object();//这2种方式创建对象是一样的,因为 ...

  3. deep-in-es6(五)

    解构 Destructuring: 解构赋值允许使用类似数组或对象字面量的语法将数组和对象的属性赋值给给中变量. 一般情况访问数组中的前三个元素: var first = arr[0]; var se ...

  4. noi2019模拟测试赛(四十七)

    noi2019模拟测试赛(四十七) T1与运算(and) 题意: ​ 给你一个序列\(a_i\),定义\(f_i=a_1\&a_2\&\cdots\&a_i\),求这个序列的所 ...

  5. canvas:画布

    画布有默认宽度,如果要自己设置宽带要写在属性上 列: <canvas id = "myCanvas" width = "600" height = &qu ...

  6. buffer--cache 详解

  7. [Python's] Python's list comprehensions a

    # Python's list comprehensions are awesome. vals = [expression for value in collection if condition] ...

  8. android关键组件service服务(一)

    一. Service简单介绍 Service是android 系统中的四大组件之中的一个(Activity.Service.BroadcastReceiver.ContentProvider),它跟A ...

  9. 为您的Office文档加把锁-ADRMS的安装

    为您的Office文档加把锁-ADRMS的安装 如今不少企业越来越重视自己KM(知识管理系统)的建立对于KM的建立实施虽然可以有效地解决企业在知识管理上的问题对于一些具有商业利益关系的机密文件(例如: ...

  10. HttpUtility.UrlEncode,Server.UrlEncode 的区别

    引用: 1.HttpUtility.UrlEncode,HttpUtility.UrlDecode是静态方法,而Server.UrlEncode,Server.UrlDecode是实例方法. 2.Se ...