uva 11995 判别数据类型
Problem I
I Can Guess the Data Structure!
There is a bag-like data structure, supporting two operations:
1 x
Throw an element x into the bag.
2
Take out an element from the bag.
Given a sequence of operations with return values, you're going to guess the data structure. It is a stack (Last-In, First-Out), a queue (First-In, First-Out), a priority-queue (Always take out larger elements first) or something else that you can hardly imagine!
Input
There are several test cases. Each test case begins with a line containing a single integer n (1<=n<=1000). Each of the next n lines is either a type-1 command, or an integer 2 followed by an integer x. That means after executing a type-2 command, we get an element x without error. The value of x is always a positive integer not larger than 100. The input is terminated by end-of-file (EOF). The size of input file does not exceed 1MB.
Output
For each test case, output one of the following:
stack
It's definitely a stack.
queue
It's definitely a queue.
priority queue
It's definitely a priority queue.
impossible
It can't be a stack, a queue or a priority queue.
not sure
It can be more than one of the three data structures mentioned above.
Sample Input
6
1 1
1 2
1 3
2 1
2 2
2 3
6
1 1
1 2
1 3
2 3
2 2
2 1
2
1 1
2 2
4
1 2
1 1
2 1
2 2
7
1 2
1 5
1 1
1 3
2 5
1 4
2 4
Output for the Sample Input
queue
not sure
impossible
stack
priority queue 题目大意:根据数据的操作<1>插入<2>删除判别是哪一种数据类型,有栈、队列、优先队列几种类型,如三种
都不符合输出impossbile,符合两种以上输出not sure,只符合一种的对应输出它的类型名称。
#include <iostream>
#include <queue>
#include <stack>
#include <cstdio>
#define Max 1010
using namespace std; int N;
int op[Max],num[Max];
stack<int> S;
queue<int> Q;
priority_queue<int> PQ;
int check_stack()
{
int i,t;
while(!S.empty()) S.pop();
for(i=;i<N;i++)
{
if(op[i]==)
{
if(S.empty()) return ;
t=S.top();S.pop();
if(t!=num[i]) return ;
}
else S.push(num[i]);
}
return ;
}
int check_queue()
{
int i,t;
while(!Q.empty()) Q.pop();
for(i=;i<N;i++)
{
if(op[i]==)
{
if(Q.empty()) return ;
t=Q.front();Q.pop();
if(t!=num[i]) return ;
}
else Q.push(num[i]);
}
return ;
}
int check_priorityqueue()
{
int i,t;
while(!PQ.empty()) PQ.pop();
for(i=;i<N;i++)
{
if(op[i]==)
{
if(PQ.empty()) return ;
t=PQ.top();PQ.pop();
if(t!=num[i]) return ;
}
else PQ.push(num[i]);
}
return ;
}
int main()
{
int i;
int s,q,pq;
while(scanf("%d",&N)!=EOF)
{
for(i=;i<N;i++) scanf("%d %d",op+i,num+i);
s=check_stack();
q=check_queue();
pq=check_priorityqueue();
if(!s && !q && !pq) printf("impossible\n");
else if(s && !q && !pq) printf("stack\n");
else if(!s && q && !pq) printf("queue\n");
else if(!s && !q && pq) printf("priority queue\n");
else printf("not sure\n");
}
return ;
}
uva 11995 判别数据类型的更多相关文章
- [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 ...
- STL UVA 11995 I Can Guess the Data Structure!
题目传送门 题意:训练指南P186 分析:主要为了熟悉STL中的stack,queue,priority_queue,尤其是优先队列从小到大的写法 #include <bits/stdc++.h ...
- 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 ...
- UVa 11995 I Can Guess the Data Structure!
做道水题凑凑题量,=_=||. 直接用STL里的queue.stack 和 priority_queue模拟就好了,看看取出的元素是否和输入中的相等,注意在此之前要判断一下是否非空. #include ...
- uva 11995 I Can Guess the Data Structure stack,queue,priority_queue
题意:给你n个操做,判断是那种数据结构. #include<iostream> #include<cstdio> #include<cstdlib> #includ ...
- 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 ...
- UVA - 11995 I Can Guess the Data Structure!(模拟)
思路:分别定义栈,队列,优先队列(数值大的优先级越高).每次放入的时候,就往分别向三个数据结构中加入这个数:每次取出的时候就检查这个数是否与三个数据结构的第一个数(栈顶,队首),不相等就排除这个数据结 ...
- 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. ...
- UVA - 11995 模拟
#include<iostream> #include<cstdio> #include<algorithm> #include<cstdlib> #i ...
随机推荐
- Sublime Text3括号配对与代码包围效果BracketHighlighter
就这么看json等配置文件,太难了,我们需要括号匹配插件BracketHighlighter,但是装完以后只有下划线提示不明显,需要配置 Bracket Settings-Default 文件 ...
- XDU——受教了
存在的问题还是很多的 GG 突然觉得刷题的目的并不是追求A.我们应该在那个过程中提高代码能力和建立模型解题能力 会的算法会巧妙应用才是王道 吐槽自己两句,写高数了
- 转过来的Xpath语法
XPath 是XML的查询语言,和SQL的角色很类似.以下面XML为例,介绍XPath 的语法. <?xml version="1.0" encoding="I ...
- 【page-monitor 前端自动化 中篇】 源码分析
转载文章:来源(靠谱崔小拽) 上篇中初探了page-monitor的一些功能和在前端自动化测试方面的可行性,本篇主要分析下page-monitor的实现方式和源码. mode-module简介 pag ...
- linux yum 安装mysql
1.安装查看有没有安装过: yum list installed MySQL* rpm -qa | grep mysql* 查看有没有安装包: yum list mysql* 安装mysql客户端: ...
- PAT (Advanced Level) Practise - 1096. Consecutive Factors (20)
http://www.patest.cn/contests/pat-a-practise/1096 Among all the factors of a positive integer N, the ...
- CSS - position属性小结
Relative: 属于文档流,针对自身进行偏移: Absolute: 脱离文档流,针对最近的定位元素进行偏移,如果没有,则针对根元素,即body标签尽心偏移: Fixed: 和absolute基本一 ...
- 一. python基础知识
第一章.变量与判断语句 1.第一个python程序 # -*- coding:utf-8 -*- # Author: Raymond print ("hello world") p ...
- 更改ubuntu的官方镜像源
我们自己安装的ubuntu通常默认镜像源是官方的,并不好用,因为网速以及限制比较多,所以为了使用方便,通常都会去更改一下默认的镜像源配置. 这里我们使用清华大学开源镜像软件站,https://mirr ...
- nginx常用功能配置
一.规范优化nginx配置文件 nginx的主配置文件为nginx.conf,主配置文件包含的所有虚拟主机的子配置文件会统一放入extra目录中,虚拟主机的配置文件按照网站的域名或功能取名,例如www ...