思路

简单题,用栈,队列,优先队列直接模拟即可

代码

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <stack>
using namespace std;
queue<int> q;
stack<int> S;
priority_queue<int> pq;
int n;
int main(){
while(scanf("%d",&n)==1){
while(!q.empty())
q.pop();
while(!S.empty())
S.pop();
while(!pq.empty())
pq.pop();
bool isS=true,isq=true,ispq=true;
for(int i=1;i<=n;i++){
int opt,x;
scanf("%d %d",&opt,&x);
if(opt==1){
q.push(x);
pq.push(x);
S.push(x);
}
else{
if(q.empty())
isq=false;
if(pq.empty())
ispq=false;
if(S.empty())
isS=false;
if(isq){
int t=q.front();
if(t!=x)
isq=false;
q.pop();
}
if(ispq){
int t=pq.top();
if(t!=x)
ispq=false;
pq.pop();
}
if(isS){
int t=S.top();
if(t!=x)
isS=false;
S.pop();
}
}
}
if((!ispq)&&(!isq)&&(!isS))
printf("impossible\n");
else if((ispq)&&(!isq)&&(!isS))
printf("priority queue\n");
else if((!ispq)&&(isq)&&(!isS))
printf("queue\n");
else if((!ispq)&&(!isq)&&(isS))
printf("stack\n");
else
printf("not sure\n");
}
return 0;
}

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

  1. 【暑假】[实用数据结构]UVa11995 I Can Guess the Data Structure!

    UVa11995  I Can Guess the Data Structure! 思路:边读边模拟,注意empty的判断! 代码如下: #include<iostream> #inclu ...

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

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

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

  4. [LeetCode] Add and Search Word - Data structure design 添加和查找单词-数据结构设计

    Design a data structure that supports the following two operations: void addWord(word) bool search(w ...

  5. [LeetCode] Two Sum III - Data structure design 两数之和之三 - 数据结构设计

    Design and implement a TwoSum class. It should support the following operations:add and find. add - ...

  6. Finger Trees: A Simple General-purpose Data Structure

    http://staff.city.ac.uk/~ross/papers/FingerTree.html Summary We present 2-3 finger trees, a function ...

  7. Mesh Data Structure in OpenCascade

    Mesh Data Structure in OpenCascade eryar@163.com 摘要Abstract:本文对网格数据结构作简要介绍,并结合使用OpenCascade中的数据结构,将网 ...

  8. ✡ leetcode 170. Two Sum III - Data structure design 设计two sum模式 --------- java

    Design and implement a TwoSum class. It should support the following operations: add and find. add - ...

  9. leetcode Add and Search Word - Data structure design

    我要在这里装个逼啦 class WordDictionary(object): def __init__(self): """ initialize your data ...

随机推荐

  1. php数组函数大全

    一.数组操作的基本函数 数组的键名和值 array_values($arr);获得数组的值 array_keys($arr);获得数组的键名 array_flip($arr);数组中的值与键名互换(如 ...

  2. laravel+阿里大于实现发送验证码短信

    一.短信服务使用阿里大于提供的短信接口 阿里大于官方网站上的接入流程: 在阿里大于申请接口后,需要做以下操作: 申请签名 申请短信模板 创建Accesskey,可以通过权限最大的Accesskey创建 ...

  3. 小tip: transition与visibility

    一.transition与visibility 这里的transition指的就是CSS3中的那个过渡动画属性transition. 如果我们仔细查看其支持的CSS属性值,会发现竟然有一个visibi ...

  4. 初识NLTK

    需要用处理英文文本,于是用到python中nltk这个包 f = open(r"D:\Postgraduate\Python\Python爬取美国商标局专利\s_exp.txt") ...

  5. PHP(层叠样式表,写法分类),选择器的种类)

    表单元素的取值怎么取  对应的属性值都有哪些? <span> 标签被用来组合文档中的行内元素. 注释:span 没有固定的格式表现.当对它应用样式时,它才会产生视觉上的变化. style ...

  6. winform中按钮透明的方法

    把Button设为透明的方法:1.修改 FlatAppearance属性下的BorderSize 为0  修改 FlatStyle 的属性为 Flat 2. /// <summary>// ...

  7. PHP调用接口用post方法传送json数据

    1.核心代码: <?php require("helper.php"); header('content-type:text/html;charset=utf-8'); $k ...

  8. 2、Flutter 填坑记录篇

    1.前言 之前写了一篇文章关于 flutter 初体验的一篇,https://www.cnblogs.com/niceyoo/p/9240359.html,当时一顿骚操作,然后程序就跑起来了. 隔了好 ...

  9. ORACLE---OCP培训

    闪回恢复区 SYS@orcl>show parameter recov; NAME         TYPE  VALUE------------------------------------ ...

  10. java框架之SpringCloud(1)-微服务及SpringCloud介绍

    微服务概述 是什么 业界大牛 Martin Fowler 这样描述微服务: 参考[微服务(Microservices)-微服务原作者Martin Flower博客翻译]. 下面是关于上述博客中的部分重 ...