UVA - 11995 I Can Guess the Data Structure! STL模板
2015-03-22 20:28
393 查看
题目大意:有n个操作,操作x y
x为1时表示放入1个数y
x为2时表示取出一个数并判断取出的数是否为y
完成n次操作后,要求判断这是什么数据结构
解题思路:用STL模板,记得判断是否为空
x为1时表示放入1个数y
x为2时表示取出一个数并判断取出的数是否为y
完成n次操作后,要求判断这是什么数据结构
解题思路:用STL模板,记得判断是否为空
[code]#include<cstdio> #include<cstring> #include<queue> #include<stack> using namespace std; int n; void solve() { int ans = 7, x, y, t, mark_S = 1, mark_Q = 1, mark_P = 1; priority_queue<int > pri_que; queue<int > q; stack<int > s; for(int i = 0; i < n; i++) { scanf("%d%d", &x, &y); if(x == 1) { s.push(y); pri_que.push(y); q.push(y); } else if(x == 2) { if(mark_S) { if(s.empty()) { mark_S = 0; } else { t = s.top(); s.pop(); if(t != y) mark_S = 0; } } if(mark_Q) { if(q.empty()) mark_Q = 0; else { t = q.front(); q.pop(); if(t != y) mark_Q = 0; } } if(mark_P) { if(pri_que.empty()) mark_P = 0; else { t = pri_que.top(); pri_que.pop(); if(t != y) mark_P = 0; } } } } if(mark_P && !mark_S && !mark_Q) printf("priority queue\n"); else if(mark_Q && !mark_S && !mark_P) printf("queue\n"); else if(mark_S && !mark_P && !mark_Q) printf("stack\n"); else if(!mark_S && !mark_P && !mark_Q) printf("impossible\n"); else printf("not sure\n"); } int main() { while(scanf("%d", &n) == 1) { solve(); } return 0; }
相关文章推荐
- UVA 11995 I Can Guess the Data Structure!(STL应用)
- UVa 11995 I Can Guess the Data Structure!
- uva11995 I Can Guess the Data Structure!(try to use simple structures)
- 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!(STL应用)
- uva 11995 I Can Guess the Data Structure!
- UVA11995 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! (STL)
- UVa 11995 I Can Guess the Data Structure!
- 水题(I Can Guess the Data Structure!,UVA 11995)
- UVA 11995 I Can Guess the Data Structure!【模拟】