Uva-11995-I Can Guess the Data Structure!
来源:互联网 发布:淘宝店铺首页怎么弄 编辑:程序博客网 时间:2024/06/10 21:53
这个题就是给你2个操作,让你根据这些操作判断这些操作数据哪种类型(队列,栈,优先队列)。
用C++ STL模拟一下就可以了,注意可能出现同时满足2种类型以及可能一种都不满足的情况。
代码:
#include<cstdio>#include<cstring>#include<iostream>#include<queue>#include<stack>using namespace std;int main(){ int n; while(scanf("%d",&n)!=EOF) {int op,val,isst=0,ispq=0,isq=0;queue<int> q;priority_queue<int> qq;stack<int> s;for(int i=0;i<n;i++){ scanf("%d%d",&op,&val); if(op==1) {q.push(val);qq.push(val);s.push(val); } else {int ita;if(!isq){ if(!q.empty()) {ita=q.front();q.pop();if(ita!=val) isq=1; } elseisq=1;}if(!ispq){ if(!qq.empty()) {ita=qq.top();qq.pop();if(ita!=val) ispq=1; } elseispq=1;}if(!isst){ if(!s.empty()) {ita=s.top();s.pop();if(ita!=val) isst=1; } elseisst=1;} }}int sum=ispq+isst+isq;if(sum==3){ printf("impossible\n"); continue;}if(sum<2){ printf("not sure\n");}else{ if(!isq)printf("queue\n"); else if(!ispq)printf("priority queue\n"); elseprintf("stack\n");} } return 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
- 普通JAVA类 如何获取,WEB项目的根路径_百度知道
- 计算机科学中最重要的32个算法
- J2SE常用包的含义
- HTML5 技术站点
- DataGridView.AutoGenerateColumns 属性
- Uva-11995-I Can Guess the Data Structure!
- 黑马程序员 笔记(九)——面向对象(内部类)
- YII 返回视图3种方式
- Oracle 使用RMAN COPY 移动 整个数据库 位置 示例
- Activity 启动模式
- indy组件在2010的重装
- jquery读取json格式
- 我来理解extern "C"
- GCC学习笔记