uva11995 I Can Guess the Data Structure!(基本数据结构)
来源:互联网 发布:ubuntu openssh国内源 编辑:程序博客网 时间:2024/04/29 19:00
题意:给定一系列操作,让你判断是否是栈,队列,优先队列
思路:直接用STL的模拟一波就好了
#include<iostream>#include<cstdio>#include<stack>#include<queue>#include<string>using namespace std;int main(){int n;while(scanf("%d",&n)!=EOF){ queue<int>q; stack<int>s; priority_queue<int>qq; int isqueue = 1; int isstack = 1; int ispriqueue = 1; for(int i = 1;i<=n;i++) { int op,v; scanf("%d%d",&op,&v); if(op==1) { q.push(v); s.push(v); qq.push(v); } else { if(!q.empty()) { int vv = q.front(); if(!q.empty()) q.pop(); if(vv!=v) isqueue = 0; } else isqueue = 0; if(!s.empty()) { int vv = s.top(); s.pop(); if (vv!=v) isstack = 0; } else isstack = 0; if(!qq.empty()) { int vv = qq.top(); qq.pop(); if(vv!=v) ispriqueue = 0; } else ispriqueue = 0; } } if(isstack&&isqueue&&ispriqueue) { printf("not sure\n"); } else if (!isstack && !isqueue&&!ispriqueue) { printf("impossible\n"); } else if (isstack && !isqueue && !ispriqueue) printf("stack\n"); else if (isqueue && !isstack && !ispriqueue) printf("queue\n"); else if (ispriqueue && !isstack && !isqueue) printf("priority queue\n"); else printf("not sure\n");}}
0 0
- uva11995 I Can Guess the Data Structure!(基本数据结构)
- UVA11995 I Can Guess the Data Structure!(数据结构,模拟)
- 【暑假】[实用数据结构]UVa11995 I Can Guess the Data Structure!
- 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
- uva11995 I Can Guess the Data Structure!(try to use simple structures)
- 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!
- 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!(STL)
- BaseAdapter的使用与优化
- C++实验7-最大公约数和最小公倍数
- 各种分类算法优缺点比较
- C语言宏高级用法 [总结]
- Rxjava和Retrofit相结合
- uva11995 I Can Guess the Data Structure!(基本数据结构)
- 虚拟机类加载器
- OnKeyListener键盘监听接口
- 网络爬虫--python抓取豆瓣同城北京地区活动信息
- C++实验七-数组素数排序
- L1-002. 打印沙漏
- mybatis 模糊查询
- vim不退出获取sudo权限
- 欢迎使用CSDN-markdown编辑器