uva11995(栈,队列,优先队列)
来源:互联网 发布:大宝防晒霜如何 知乎 编辑:程序博客网 时间:2024/05/02 02:20
题意:
1代表放入;
2代表拿出;
问可能是哪种数据结构;
思路:
将题目提供的三种数据结构拿进去模拟一下就行了;
#include<cstdio>#include<cstring>#include<algorithm>#include<queue>#include<stack>using namespace std;queue<int> q;stack<int> s;priority_queue<int> pq;int main() {int n;int operate, num;while(scanf("%d",&n) == 1) {while(!q.empty()) q.pop();while(!s.empty()) s.pop();while(!pq.empty())pq.pop();bool isq = 1;bool iss = 1;bool ispq = 1;while(n--) {scanf("%d%d",&operate,&num);if(operate == 1) {if(isq)q.push(num);if(iss)s.push(num);if(ispq)pq.push(num);}if(operate == 2) {if(isq) {if(q.empty())isq = 0;else {if(q.front() != num)isq = 0;elseq.pop();}}if(iss) {if(s.empty())iss = 0;else {if(s.top() != num)iss = 0;elses.pop();}}if(ispq) {if(pq.empty())ispq = 0;else {if(pq.top() != num)ispq = 0;elsepq.pop();}}}}if(iss && !isq && !ispq)printf("stack\n");else if(!iss && isq && !ispq)printf("queue\n");else if(!iss && !isq && ispq)printf("priority queue\n");else if(!iss && !isq && !ispq)printf("impossible\n");elseprintf("not sure\n");}}
0 0
- uva11995(栈,队列,优先队列)
- UVA11995 优先队列
- 栈、队列、优先队列
- 栈,队列,优先队列
- STL--优先队列,队列,栈
- 栈、队列和优先队列
- STL-栈,队列,优先队列
- 栈、队列与优先队列
- 栈+队列+优先队列-总结
- 栈、队列、优先队列笔记
- 优先队列实现栈
- 关于栈,优先队列
- 优先队列 队列 栈 的使用方法
- STL 优先队列、队列、栈的使用
- STL 栈,队列,优先队列用法
- STL 优先队列、队列、栈的用法
- STL 优先队列(队列+栈) 转载
- STL优先队列,队列,栈的使用
- 与后台返回数据类型老是出错(文档和现实老是对接不上)
- 第5篇 装饰者模式
- C#学习
- Sicily 1407. Plaque Pack
- 【c语言】有一个分数序列 2/1+3/2+5/3+8/5+13/8+… 求出这个数列前20项的和
- uva11995(栈,队列,优先队列)
- Sicily 1444. Prime Path
- SharedPreferences 学习
- 【c语言】一个球从100米高的自由落下,每次落地后反跳回原高度的一半,再落下,再反弹。求第 10次落地时,共经过多少米,第10次反弹多高。
- 转 -- 精通 Oracle+Python,第 1 部分:查询最佳应践
- WIN32 API 函数之——打印函数
- Sicily 1497. Wavelet Compression
- Windows Shell 扩展编程 第十五章
- sizeof计算结构体的大小