UVA 11995 I Can Guess the Data Structure! (STL的应用)
2014-05-17 22:02
483 查看
思路:需要模拟栈,队列,优先队列,看看输入满足以上的哪一种情况
#include <cstdio> #include <cmath> #include <iostream> #include <algorithm> #include <string> #include <cstring> #include <stdlib.h> #include <stack> #include <queue> #include <iterator> #include <set> #include <ctype.h> using namespace std; int main() { int n; while(~scanf("%d", &n)) { int x, y; bool iss = true, isq = true, ispq = true; stack <int> s; queue <int> q; priority_queue <int> pq; for(int i = 0; i < n; i++) { scanf("%d%d", &x, &y); if(x == 1) { s.push(y); q.push(y); pq.push(y); } else { if(iss) { if(!s.empty() && y == s.top()) s.pop(); else iss = false; } if(isq) { if(!q.empty() && y == q.front()) q.pop(); else isq = false; } if(ispq) { if(!pq.empty() && y == pq.top()) pq.pop(); else ispq = false; } } } if(iss && !isq && !ispq) puts("stack"); else if(!iss && isq && !ispq) puts("queue"); else if(!iss && !isq && ispq) puts("priority queue"); else if(!iss && !isq && !ispq) puts("impossible"); else puts("not sure"); } return 0; }
相关文章推荐
- 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应用)
- STL 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!(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 11995 I Can Guess the Data Structure!(ADT)
- UVa 11995 I Can Guess the Data Structure!
- 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!
- uva 11995 I Can Guess the Data Structure!