UVa11995  I Can Guess the Data Structure!

思路:边读边模拟,注意empty的判断!

代码如下:

#include<iostream>
#include<queue>
#include<stack>
using namespace std; int main(){
queue<int> q;
priority_queue<int> pri_q;
stack<int> sta;
int n;
while(cin>>n){
while(!q.empty()) q.pop(); //清空data
while(!pri_q.empty()) pri_q.pop();
while(!sta.empty()) sta.pop(); int a,b,c; a=b=c=;
while(n--) {
int op,x;
cin>>op>>x;
if(op == ){
if(a) q.push(x);
if(b) pri_q.push(x);
if(c) sta.push(x);
}
else {
if(a) if(q.empty()) a=; else {a= q.front()==x; q.pop();}
if(b) if(pri_q.empty()) b=; else{b= pri_q.top()==x; pri_q.pop();}
if(c) if(sta.empty()) c=; else{c= sta.top()==x; sta.pop();}
}
}
if(!a && !b &&!c) cout<<"impossible";
else
if((a&&b) || (a&&c) ||(b&&c)) cout<<"not sure";
else{
if(a) cout<<"queue";
else if(b) cout<<"priority queue";
else cout<<"stack";
}
cout<<"\n";
}
return ;
}

【暑假】[实用数据结构]UVa11995 I Can Guess the Data Structure!的更多相关文章

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

  2. UVA11995 I Can Guess the Data Structure!

    思路 简单题,用栈,队列,优先队列直接模拟即可 代码 #include <cstdio> #include <algorithm> #include <cstring&g ...

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

  5. 面试总结之数据结构(Data Structure)

    常用数据结构及复杂度 http://www.cnblogs.com/gaochundong/p/3813252.html 常用数据结构的时间复杂度 Data Structure Add Find De ...

  6. 【暑假】[实用数据结构]UVAlive 3135 Argus

    UVAlive 3135 Argus Argus Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %l ...

  7. 【暑假】[实用数据结构]UVa11991 Easy Problem from Rujia Liu?

    UVa11991 Easy Problem from Rujia Liu?  思路:  构造数组data,使满足data[v][k]为第k个v的下标.因为不是每一个整数都会出现因此用到map,又因为每 ...

  8. 【暑假】[实用数据结构]范围最小值问题(RMQ)

    范围最小值问题: 提供操作: Query(L,R):计算min{AL ~ AR } Sparse-Table算法: 定义d[i][j]为从i开始长度为2j的一段元素的最小值.所以可以用递推的方法表示. ...

  9. 【暑假】[实用数据结构]UVAlive 3026 Period

    UVAlive 3026 Period 题目: Period   Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld ...

随机推荐

  1. centos下hadoop2.6.0集群搭建详细过程

    一 .centos集群环境配置 1.创建一个namenode节点,5个datanode节点 主机名 IP namenodezsw 192.168.129.158 datanode1zsw 192.16 ...

  2. C#中用JavaScriptSerializer和Json.Net操作json格式的文件

    1.json文件 2.写出对应的类 //折扣 public class Discount { public string Qty { get; set; } public string percent ...

  3. MSSQLServer基础06(变量,case,选择语句)

    变量 声明:declare @UserName nvarchar(50) 赋值1:set @UserName=N'杨':修改 赋值2:select @UserName=N'牛':修改 输出:print ...

  4. 256. Paint House

    题目: There are a row of n houses, each house can be painted with one of the three colors: red, blue o ...

  5. Android之NDK编程(JNI)

    转自:http://www.cnblogs.com/xw022/archive/2011/08/18/2144621.html NDK编程入门--C回调JAVA方法   一.主要流程 1.  新建一个 ...

  6. web前端性能测试小点

    关于前端性能的文章: http://www.cnblogs.com/fnng/archive/2011/09/19/2181894.html web应用的前端性能响应时间指浏览器的页面加载时间.浏览器 ...

  7. C#获取一个文件的扩展名

    C#获取一个文件的扩展名System.IO.Path.GetExtension( "文件名 ");ChangeExtension   更改路径字符串的扩展名. Combine   ...

  8. [Codeforces137C]History(排序,水题)

    题目链接:http://codeforces.com/contest/137/problem/C 题意:给n对数,分别是一个事件的起始和终止时间.问被有几个事件被其他事件包含. 思路:先排序,按照起始 ...

  9. int string相互转换

    一.itoa()和atoi() 注意:这两个函数并不是标准的C函数,而是windows环境下特有的函数. 1.itoa #include<iostream> #include<str ...

  10. zlib代码生成

    1.主页下载zlib-1.2.8的source code的压缩包:F:\Develop Tools\zlib-1.2.8 2.下载安装cmake-2.8.1-win32-x86 3.用cmake生成z ...