做道水题凑凑题量,=_=||。

直接用STL里的queue、stack 和 priority_queue模拟就好了,看看取出的元素是否和输入中的相等,注意在此之前要判断一下是否非空。

 #include <bits/stdc++.h>
using namespace std; void scan( int &x )
{
char c;
while( c = getchar(), c < '' || c > '' );
x = c - '';
while( c = getchar(), c >= '' && c <= '' ) x = x* + c - '';
} const int maxn = + ;
int t[maxn], d[maxn]; bool is_queue(int n)
{
queue<int> Q;
for(int i = ; i < n; i++)
{
if(t[i] == ) Q.push(d[i]);
else
{
if(Q.empty()) return false;
int x = Q.front(); Q.pop();
if(x != d[i]) return false;
}
}
return true;
} bool is_stack(int n)
{
stack<int> S;
for(int i = ; i < n; i++)
{
if(t[i] == ) S.push(d[i]);
else
{
if(S.empty()) return false;
int x = S.top(); S.pop();
if(x != d[i]) return false;
}
}
return true;
} bool is_p_queue(int n)
{
priority_queue<int> Q;
for(int i = ; i < n; i++)
{
if(t[i] == ) Q.push(d[i]);
else
{
if(Q.empty()) return false;
int x = Q.top(); Q.pop();
if(x != d[i]) return false;
}
}
return true;
} int main()
{
//freopen("in.txt", "r", stdin); int n;
while(scanf("%d", &n) == )
{
for(int i = ; i < n; i++) { scan(t[i]); scan(d[i]); }
bool f1 = is_queue(n);
bool f2 = is_stack(n);
bool f3 = is_p_queue(n);
int cnt = (int)f1 + (int)f2 + (int)f3;
if(cnt > ) puts("not sure");
else if(cnt == ) puts("impossible");
else
{
if(f1) puts("queue");
if(f2) puts("stack");
if(f3) puts("priority queue");
}
} return ;
}

代码君

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

  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 stack,queue,priority_queue

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

  7. UVA - 11995 I Can Guess the Data Structure!(模拟)

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

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

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

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

随机推荐

  1. Careercup - Facebook面试题 - 4713484755402752

    2014-05-02 00:30 题目链接 原题: Given two arrays of sorted integers, merge them keeping in mind that there ...

  2. Unity3d修改FBX文件的动画名方法

    问题描述:FBX文件导入Unity3d后的动画名字一般都是 “Take 001”并且无法修改!如何修改它呢? 解决方法:解决方法其实很简单,只要你按照Unity3d的FBX文件命名规则,压根就不会存在 ...

  3. 提交jar作业到spark上运行

    1.引入spark包:spark-assembly-1.4.0-hadoop2.6.0,在spark的lib目录下 File-->project structure 2.用IDEA建立一个sca ...

  4. PHP中发送邮件的几种方法总结

    1. 使用 mail() 函数 没什么好讲的,就是使用系统自带的smtp系统来发送,一般是使用sendmail来发.这个按照各个系统不同而定.使用参考手册. 2. 使用管道的形式 昨天刚测试成功,使用 ...

  5. PowerDesigner 逆向工程 从SQL文件转换成PDM 从PDM转成CDM

    从SQL文件逆向工程到PDM: ①选择file -> Reverse Engineer - > Database ②在General选项卡中选择MySQL数据库,点击确定. ③using ...

  6. lintcode :数组剔除元素后的乘积

    题目: 数组剔除元素后的乘积 给定一个整数数组A. 定义B[i] = A[0] * ... * A[i-1] * A[i+1] * ... * A[n-1], 计算B的时候请不要使用除法. 样例 给出 ...

  7. *[topcoder]LCMSetEasy

    http://community.topcoder.com/stat?c=problem_statement&pm=13040 DFS集合全排列+LCM和GCD.但事实上,有更简单的算法,列在 ...

  8. 是谁决定了走redis缓存?当然是mybatis啊

    1.是谁决定了走redis缓存?当然是mybatis啊 mybatis里默认实现数据的增删改查功能,这里要用到缓存啊 而且是mybatis这种orm框架采用缓存机制的,mybatis默认都有两层缓存了 ...

  9. 2.Sprng-IoC-Java反射例子

    1.Car.java package com.jike.spring.chapter03.reflect; public class Car { private String brand; priva ...

  10. 基于QT的换肤整体解决方案(QSkinStyle)(提供Linux的XP风格)

    基于QT的换肤整体解决方案(QSkinStyle) 对QT这个成功的跨平台GUI库,本身内置了对换肤功能的实现,比如cleanlooks.plastique等跨平台风格:还有一些是和平台相关的风格,比 ...