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. 255. Verify Preorder Sequence in Binary Search Tree

    题目: Given an array of numbers, verify whether it is the correct preorder traversal sequence of a bin ...

  2. C# 使用ManualResetEvent 进行线程同步

    上一篇我们介绍了AutoResetEvent,这一篇我们来看下ManualResetEvent ,顾名思义ManualResetEvent  为手动重置事件. AutoResetEvent和Manua ...

  3. python生成验证码脚本

    最近每天都用python写一个小的脚本,练习使用python语法. 验证码的生成: 这里使用了python的图像处理库PIL,安装PIL的过程中出了一个小麻烦,就使用Pillow-win32的一个文件 ...

  4. iOS开原项目

    http://www.lanrenios.com/ios/project/2013/0729/1433.html http://www.cnblogs.com/xiaobaizhu/archive/2 ...

  5. openVPN使用

    http://www.williamlong.info/archives/3814.html http://openvpn.ustc.edu.cn/ http://www.williamlong.in ...

  6. MyEclipse中使用JUnit进行单元测试

    1. 下载JUnit的jar文件,下载地址在这里 2. 在MyEclipse中新建一个要测试的项目HelloJUnit 3. 添加一个要测试的类HelloJUnit,代码如下,注意需要先建packag ...

  7. 对EditText监听,按钮点击

    1 etBarCode.addTextChangedListener(watcher); 2 private TextWatcher watcher = new TextWatcher() { @Ov ...

  8. RPi 2B Raspbian SD卡内部架构

    /***************************************************************************** * RPi 2B Raspbian SD卡 ...

  9. Java [Leetcode 223]Rectangle Area

    题目描述: Find the total area covered by two rectilinear rectangles in a 2D plane. Each rectangle is def ...

  10. 01day2

    小明搬家 模拟 [问题描述] 小明要搬家了,大家都来帮忙. 小明现在住在第N楼,总共K个人要把X个大箱子搬上N楼. 最开始X个箱子都在1楼,但是经过一段混乱的搬运已经乱掉了.最后大家发现这样混乱地搬运 ...