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

直接用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. C# ASP .NET WEB方向和WPF方向,我该如何去选择

    一个2012年南航毕业学软件的学生,该如何去选择我的职业方向? 2011年11分月份,我被老师介绍在南京珠江路华丽国际大厦工作,开发一个大型国际物流平台,公司的开发人员比较少,设计网站的是高校的老师, ...

  2. 打造自己的程序员品牌(摘自Infoq)

    John Sonmez是Simple Programmer的创始人.作者与程序员,关注于如何让复杂的事情变得简单.他是一位专业的软件开发者.架构师与讲师,感兴趣的领域包括测试驱动开发.如何编写整洁的代 ...

  3. 【转】android 内存泄漏相关收藏博客。

    关于android内存泄漏的研究   博客建了几个月,都没有去写,一是因为当时换工作,然后又是新入职(你懂的,好好表现),比较忙:二是也因为自己没有写博客的习惯了.现在还算是比较稳定了,加上这个迭代基 ...

  4. SHELL syntax error:unexpected end of file 提示错误

    SHELL syntax error:unexpected end of file 提示错误 if [ -n "$1" ] then " else " fi e ...

  5. centos nginx,php添加到Service

    SHELL脚本: nginx vim /etc/init.d/nginx #!/bin/sh # # nginx - this script starts and stops the nginx da ...

  6. Codeforces Round #302 (Div. 2) D. Destroying Roads 最短路

    题目链接: 题目 D. Destroying Roads time limit per test 2 seconds memory limit per test 256 megabytes input ...

  7. js收集的一些好的题型

    ①: var a = {x:1},b=a;var a = a.z = {Y:2}; 求a和b的值? ②:   var  w = (function a(){return '1'},function b ...

  8. oracle——merge

      一.概述 使用merge声明从一个或者更多个表或视图中筛选记录,以用来更新或者插入到一个表或视图中.你可以指定条件以决定是执行update操作还是insert操作到目标表或视图中. 这个声明是一个 ...

  9. watch your tone

    老板要求邮件注意语气... 木想到混了这么久这种事情还要老板提醒

  10. 【WCF--初入江湖】06 WCF契约服务行为和异常处理

    06 WCF契约服务行为和异常处理 一.WCF契约服务行为 [1] 服务行为可以修改和控制WCF服务的运行特性. 在实现了WCF服务契约后,可以修改服务的很多执行特性. 这些行为(或者特性)是通过配置 ...