UVA 11995 I Can Guess the Data Structure!
来源:互联网 发布:怎样写淘宝直通车标题 编辑:程序博客网 时间:2024/06/07 23:18
题目大意:
直接见白书。
解题思路:
简单的STL应用,直接上代码。
小结一下:
1.stack: top(),push();
2.queue: front(),push();
3.priority_queue:top(),push();
4.使用之前一定要判断!empty();
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>#include<queue>#include<stack>using namespace std;stack<int> st;queue<int> q;priority_queue<int> pr;void init(){ while(!st.empty()) { st.pop(); } while(!q.empty()) { q.pop(); } while(!pr.empty()) { pr.pop(); }}int main(){ int n; int a,b; while(scanf("%d",&n)==1) { init(); int f1=1,f2=1,f3=1; for(int i=0;i<n;i++) { scanf("%d %d",&a ,&b); if(a==1) { st.push(b); q.push(b); pr.push(b); } else if(a==2) { int c; if( (!st.empty()) && b==st.top()) { st.pop(); } else { f1=0; } if( (!q.empty()) && b==q.front()) { q.pop(); } else { f2=0; } if( (!pr.empty()) && b==pr.top()) { pr.pop(); } else { f3=0; } } } int cnt=f1+f2+f3; if(cnt>=2) { printf("not sure\n"); } else if(cnt==0) { printf("impossible\n"); } else { if(f1) { printf("stack\n"); } else if(f2) { printf("queue\n"); } else if(f3) { printf("priority queue\n"); } } } 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!(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)
- 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!
- 11995 - I Can Guess the Data Structure! uva
- 在编写JSON数据时java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeExcepti
- Vim技巧5
- OpenCV支持的AVI文件格式
- Mac下Git命令汇总
- Java核心技术第4章(6)
- UVA 11995 I Can Guess the Data Structure!
- 多线程编程
- Android,Java编程小常识
- 矩阵快速幂 CodeForces - 582B Once Again...
- CI轻松整合smarty
- STL-set-用法
- os.getcwd() 返回的到底是什么?
- 文本分类入门(番外篇)特征选择与特征权重计算的区别
- Java复习笔记—面向对象