uva 11995 I Can Guess the Data Structure!(数据结构:基础)
来源:互联网 发布:淘宝视频制作 编辑:程序博客网 时间:2024/05/16 05:26
很水的一道题啊,考察对STL栈、队列、优先队列的基础运用
代码如下:
#include <cstdio>#include <stack>#include <queue>#include <iostream>#include <algorithm>using namespace std;stack<int> st;queue<int> qu;priority_queue<int, vector<int>, less<int> > pq;int st_num, qu_num, pq_num;void init() { while(!st.empty()) st.pop(); st_num = 0; while(!qu.empty()) qu.pop(); qu_num = 0; while(!pq.empty()) pq.pop(); pq_num = 0;}int main(void) { int n, i, c, d, cnt; while(scanf("%d", &n) != EOF) { init(); cnt = 0; for(i=0; i<n; ++i) { scanf("%d%d", &c, &d); if(c == 1) { st.push(d); qu.push(d); pq.push(d); } else { cnt++; if(!st.empty() && st.top() == d) { st_num++; st.pop(); } if(!qu.empty() && qu.front()==d) { qu_num++; qu.pop(); } if(!pq.empty() && pq.top() == d) { pq_num++; pq.pop(); } } } //cout << st_num << endl << qu_num << endl << pq_num << endl; if(st_num==cnt && qu_num!=cnt && pq_num!=cnt) { cout << "stack" << endl; } else if(st_num!=cnt && qu_num==cnt && pq_num!=cnt) { cout << "queue" << endl; } else if(st_num!=cnt && qu_num!=cnt && pq_num==cnt) { cout << "priority queue" << endl; } else if(st_num!=cnt && qu_num!=cnt && pq_num!=cnt) { cout << "impossible" << endl; } else { cout << "not sure" << endl; } } return 0;}
0 0
- uva 11995 I Can Guess the Data Structure!(数据结构:基础)
- UVA 11995 - I Can Guess the Data Structure! (基本数据结构)
- uva 11995 I Can Guess the Data Structure 数据结构
- 【模拟+数据结构】UVA 11995 I Can Guess the Data Structure!
- UVA - 11995 - I Can Guess the Data Structure! (基础数据结构练习!)
- uva - 11995 - I Can Guess the Data Structure!
- Uva-11995-I Can Guess the Data Structure!
- Uva 11995 - I Can Guess the Data Structure!
- UVA 11995 I Can Guess the Data Structure!
- uva 11995 I Can Guess the Data Structure!
- uva 11995 I Can Guess the Data Structure!(STL)
- UVA 11995 I Can Guess the Data Structure!
- UVA 11995 I Can Guess the Data Structure!
- uva 11995 - I Can Guess the Data Structure!
- Uva 11995 - I Can Guess the Data Structure! (判断数据类型)
- UVa:11995 I Can Guess the Data Structure!
- UVA - 11995 I Can Guess the Data Structure!
- UVa 11995 I Can Guess the Data Structure! (STL)
- 玩转STM32F0 Value Line Discovery 之 点亮LED
- DLL编程基础
- ubuntu下的c语言的第一天
- Array和ArrayList的异同点
- Makefile经典教程(掌握这些足够)
- uva 11995 I Can Guess the Data Structure!(数据结构:基础)
- NandFlash简介
- Linux下完美驱动HTC Android手机的Internet传输(通过USB共享电脑网络)
- POJ1151 Atlantis 【扫描线】
- VMware中CentOS设置静态IP
- 博弈---ZOJ 3057 Beans Game(DP博弈)
- poj 1182 食物链
- JavaScript 常见陷阱
- 10-hibernate组件关联关系映射