I Can Guess the Data Structure!
来源:互联网 发布:nginx for linux 安装 编辑:程序博客网 时间:2024/05/31 19:43
#include<iostream>#include<stack>#include<queue>#include<stdio.h>using namespace std;int a[10110][10];int main(){stack<int> s;queue<int> q;priority_queue<int> pq;int t;while(cin>>t){int i;while(!s.empty()){s.pop();}while(!q.empty()){q.pop();}while(!pq.empty()){pq.pop();}for(i=0;i<t;i++){cin>>a[i][0]>>a[i][1];}int sum=0;int flags=1,flagq=1,flagpq=1;int flag=1;int one=0,two=0;for(i=0;i<t;i++){if(a[i][0]==1){one++;s.push(a[i][1]);q.push(a[i][1]);pq.push(a[i][1]);}else if(a[i][0]==2){two++;if(!s.empty()&&a[i][1]!=s.top()&&flags==1){flags=0;}if(!q.empty()&&a[i][1]!=q.front()&&flagq==1){flagq=0;}if(!pq.empty()&&a[i][1]!=pq.top()&&flagpq==1){flagpq=0;}if(!pq.empty())pq.pop();if(!s.empty())s.pop();if(!q.empty())q.pop();}}sum=flags+flagq+flagpq;if(sum==0){cout<<"impossible"<<endl;}else if(sum==1){if(flags){cout<<"stack"<<endl;}else if(flagq){cout<<"queue"<<endl;}else{cout<<"priority queue"<<endl;}}else{if(two>one){ //注意对输入样例的临界处的情况的考虑,这里如果当n=1是有IN和OUT两种情况,如果为IN为not surecout<<"impossible"<<endl; //如果为OUT应该是imposible.还有其他情况:当num(OUT)>num(in),输出为impossible。}else{cout<<"not sure"<<endl;}}}return 0;}
0 0
- 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!
- I Can Guess the Data Structure! uva11995
- 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)
- 【计算机网络-4】 【第三章】数据链路层笔记1——组帧、差错控制、流量控制
- 测试PHP服务端是否支持SSL
- dwr框架的入门
- 用Python读写Excel文件
- Matlab面向对象编程的两种方式
- I Can Guess the Data Structure!
- echarts 条形图异步加载数据
- [李景山php]每天laravel-20161014|Validator.php-14
- BZOJ3037 创世纪
- 错误记录五
- Git深度使用经验总结
- ViewPager结合自定义View产生滑动pager下方有效圆点变动显示的效果
- UVA494 Kindergarten Counting Game
- file_get_contents获取https出错的解决办法