UVA11995----数据结构水题
来源:互联网 发布:现在的淘宝店好做吗 编辑:程序博客网 时间:2024/05/18 03:41
题目地址:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3146
这个题目的意思很简单,给你一些push和pop操作,然后根据操作的结果来猜数据结构。
就三种,
stack
queue
priority queue
正好用STL就可以模拟。
但是模拟的时候要注意,在pop的时候,STL中的可能已经为空了。所以要加个判断进去。
下面看我的代码:
#include<cstdio>#include<cstring>#include<stack>#include<queue>using namespace std;stack<int> a;queue<int> b;priority_queue<int> c;int main(){ int n; while(~scanf("%d",&n)) { int x,y; while(!a.empty()) a.pop(); while(!b.empty()) b.pop(); while(!c.empty()) c.pop(); bool aa,bb,cc; aa=bb=cc=true; while(n--) { scanf("%d%d",&x,&y); if(x==1) { a.push(y); b.push(y); c.push(y); } else { if(!a.empty()) { int aaa = a.top(); a.pop(); if(aaa!=y) aa=false; } else aa=false; if(!b.empty()) { int bbb = b.front(); b.pop(); if(bbb!=y) bb=false; } else bb=false; if(!c.empty()) { int ccc = c.top(); c.pop(); if(ccc!=y) cc=false; } else cc=false; } } if((aa&&bb) || (aa&&cc) || (bb&&cc)) printf("not sure\n"); else if(aa) printf("stack\n"); else if(bb) printf("queue\n"); else if(cc) printf("priority queue\n"); else printf("impossible\n"); } return 0;}
- UVA11995----数据结构水题
- uva11995基础数据结构
- 例题3.1 猜猜数据结构 UVa11995
- uva11995
- 【暑假】[实用数据结构]UVa11995 I Can Guess the Data Structure!
- uva11995 I Can Guess the Data Structure!(基本数据结构)
- UVA11995 I Can Guess the Data Structure!(数据结构,模拟)
- UVA11995【I can guess the data structrue!!】【水】+UVA11991【map用法】
- UVA11995 优先队列
- uva11995--水题(训练指南)
- uva11995(栈,队列,优先队列)
- I Can Guess the Data Structure! UVA11995
- UVa11995 I Can Guess the Data Structure!
- UVA11995:I Can Guess the Data Structure
- I Can Guess the Data Structure! uva11995
- 数据结构题
- 数据结构题
- 数据结构题
- TH-KGC高压开关测试仪
- sizeof()于strlen()函数的区别
- 细说Cookie
- linux 下文件的路径
- Html/Jsp常用的页面跳转方法
- UVA11995----数据结构水题
- 毕业设计之路(9)-ucosi操作系统移植到STM32
- 配置和启用VPN远程访问服务
- Spring MVC的工作机制
- Linux下删除大量小文件
- (转)Android游戏开发之处理音乐与音效太鼓达人游戏原理(二十一)
- Flex中處理窗口大小變化
- IOS开发(5)之UISegmentedControl控件
- 两个简单例子揭示makefile中“=”和“:=”的区别