题意:给你n个操做,判断是那种数据结构。

 #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
using namespace std;
int n;
int v[],u[]; int ck_q()
{
//cout<<"!!"<<endl;
queue<int>s;
for(int i=; i<n; i++)
{
if(v[i]==)
{
if(s.empty())
return ;
int x=s.front();
s.pop();
if(x!=u[i])
return ;
}
else
s.push(u[i]);
}
return ;
} int ck_s()
{
stack<int>s;
for(int i=; i<n; i++)
{
if(v[i]==)
{
if(s.empty())
return ;
int x=s.top();
s.pop();
if(x!=u[i])
return ;
}
else
s.push(u[i]);
}
return ;
} int ck_d()
{
priority_queue<int>s;
for(int i=; i<n; i++)
{
if(v[i]==)
{
if(s.empty())
return ;
int x=s.top();
s.pop();
if(x!=u[i])
return ;
}
else
s.push(u[i]);
}
return ;
}
int main()
{
while(~scanf("%d",&n))
{
for(int i=; i<n; i++)
{
scanf("%d%d",&v[i],&u[i]);
}
int s=ck_s();
int q=ck_q();
int d=ck_d();
//cout<<s<<" "<<q<<" "<<d<<endl;
if(s&&!q&&!d)
printf("stack\n");
else if(!s&&q&&!d)
printf("queue\n");
else if(!s&&!q&&d)
printf("priority queue\n");
else if(!s&&!q&&!d)
printf("impossible\n");
else
printf("not sure\n");
}
return ;
}

uva 11995 I Can Guess the Data Structure stack,queue,priority_queue的更多相关文章

  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!

    做道水题凑凑题量,=_=||. 直接用STL里的queue.stack 和 priority_queue模拟就好了,看看取出的元素是否和输入中的相等,注意在此之前要判断一下是否非空. #include ...

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

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

  8. [Data Structure] Stack Implementation in Python

    We can realize a Stack as an adaptation of a Python List. S.push(e)=L.append(e) S.pop()=L.pop() S.to ...

  9. Data Structure Stack: Reverse a stack using recursion

    http://www.geeksforgeeks.org/reverse-a-stack-using-recursion/ #include <iostream> #include < ...

随机推荐

  1. 在SpringMVC利用MockMvc进行单元测试

    spring在线文档:https://docs.spring.io/spring/docs/current/javadoc-api/index.html?index-files/index-13.ht ...

  2. easyui 使特定tab处于选中状态

    <div id="tabs" class="easyui-tabs"> <div title="Tab1" style=& ...

  3. The 7th Zhejiang Provincial Collegiate Programming Contest->Problem G:G - Wu Xing

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3328 至今未看懂题意,未编译直接提交,然后 A了.莫名AC总感觉怪怪的. ...

  4. linux网络环境配置

    第一种方法: (red hat) (1)用root身份登录,运行setup命令进入到text mode setup utility 对网络进行配置,这里可以进行ip,子网掩码,默认网关,dns的设置. ...

  5. loadrunner java协议脚本要点

    常见问题 1. Error: Thread Context: Call to service of the driver failed, reason - thread context wasn't ...

  6. Java知识大全

    http://blog.csdn.net/zhangerqing/article/details/8245560

  7. beyond compare ftp 文件夹同步

    因为经常要同步服务器上的代码,今天试了一下beyond compare 的ftp同步非常爽.以前都只用了beyond compare的文件夹比较功能了,ftp功能没有使用过. 步骤1:点击:会话——& ...

  8. editplus的配置文件来支持sql语法高亮【转】

      editplus默认是没有sql语法高亮的,原因是它的内部没有sql.stx的这样一个语法文件 我们自己在 EditPlus 的安装目录下面新建一个文件名为sql.stx,然后打开editplus ...

  9. 绕过图片格式限制上传木马获取WebShell

    思路: 图片上传功能中,前端页面上传的是.png格式的图片文件,但是抓包Request中修改图片后缀为.php 可以绕过对上传文件格式的限制,文件的上传路径可以在上传后的页面或查看上传成功后的resp ...

  10. php cloure闭包

    Closures 它可以让您创建in-line 函数.许多语言已经开始有此功能了,也许您在不知道的情况下也使用过它. 例如: <?php $myFunction = function() { e ...