uva 11995(stl)
来源:互联网 发布:淘宝中秋节活动logo 编辑:程序博客网 时间:2024/04/25 14:55
题意:1 x,表示放进x元素,2表示拿出一个元素,给出n条指令,然后2 x表示取出的数据是什么,问可以从输入输出判断出是哪种数据结构(栈,队列,优先队列),如果有多种满足,就输出not sure,都不是就输出impossible。
题解:直接定义三个数据结构的stl变量,然后模拟放入数据,到拿出数据时和三种比对判断,可以知道是哪种数据结构。
#include <stdio.h>#include <queue>#include <stack>using namespace std;const int N = 1000;int n;queue<int> q1;stack<int> s;priority_queue<int> q2;void init() {while (!q1.empty())q1.pop();while (!q2.empty())q2.pop();while (!s.empty())s.pop();}int main() {while (scanf("%d", &n) == 1) {int a, x, num1 = 0, num2 = 0, num3 = 0, cnt = 0;init();for (int i = 0; i < n; i++) {scanf("%d%d", &a, &x);if (a == 1) {q1.push(x);q2.push(x);s.push(x);}else {cnt++;int temp1 = -1, temp2 = -1, temp3 = -1;if (!q1.empty()) {temp1 = q1.front();q1.pop();}if (!q2.empty()) {temp2 = q2.top();q2.pop();}if (!s.empty()) {temp3 = s.top();s.pop();}if (temp1 == x)num1++;if (temp2 == x)num2++;if (temp3 == x)num3++;}}if (num1 == cnt && num2 == cnt || num2 == cnt && num3 == cnt || num1 == cnt && num3 == cnt)printf("not sure\n");else if (num1 == cnt)printf("queue\n");else if (num2 == cnt)printf("priority queue\n");else if (num3 == cnt)printf("stack\n");elseprintf("impossible\n");}return 0;}
0 0
- uva 11995 STL模拟
- uva 11995(stl)
- uva 11995 猜测数据结构 入门与STL
- UVA 11995 (STL应用 13.08.07)
- uva 673( c++ STL)
- UVa - 156 Ananagrams(STL)
- UVa-101(STL)
- UVA 11729 STL
- 【STL】uva 514 Rails
- uva 156 Ananagrams STL
- uva 11995 I Can Guess the Data Structure!(STL)
- UVa 11995 I Can Guess the Data Structure! (STL)
- UVA 11995 I Can Guess the Data Structure!(STL应用)
- UVA - 11995 I Can Guess the Data Structure! STL模板
- UVA 11995 - I Can Guess the Data Structure!【stl】
- uva 10282 Babelfish(STL map)
- uva 10954 Add All(STL)
- UVa 10282 - Babelfish STL Map
- View inflate(resId, ViewGroup , boolean attachToRoot)和View inflate(int resource, ViewGrou)区别
- fragment跳转到activity返回卡顿
- 矩阵乘幂
- 百度地图定位功能实例
- Codeforces Round #166 (Div. 2)---D. Good Substrings(字符串)
- uva 11995(stl)
- 类的概述和举例
- 织梦DedeCMS调用二级子栏目或者多级栏目解决方法
- 为什么新产品上市时要进行产品研究?
- Python多进程并发(multiprocessing)
- java反射
- java内存回收机制
- dojo 操作元素
- linux设备驱动第四篇:从如何定位oops的代码行谈驱动调试方法