uva 11995 I Can Guess the Data Structure!
2015-09-14 22:51
423 查看
思路;分别模拟三种数据结构,观察输出是否对应
#include <iostream> #include <stdio.h> #include <cstring> #include <queue> #include <stack> using namespace std; int main() { //freopen("in.txt","r",stdin); int n; while(scanf("%d",&n)!=EOF) { //printf("%d",n); int f1=1,f2=1,f3=1; queue <int >q1; priority_queue<int>q2; stack<int> q3; int x,y; for(int i=0;i<n;i++) { scanf("%d%d",&x,&y); if(x==1) { q1.push(y); q2.push(y); q3.push(y); } else if(x==2) { int tmp; if(!q1.empty()) { tmp=q1.front(); q1.pop(); if(tmp!=y) f1=0; } else f1=0; if(!q2.empty()) { tmp=q2.top(); q2.pop(); if(tmp!=y) f2=0; } else f2=0; if(!q3.empty()) { tmp=q3.top(); q3.pop(); if(tmp!=y) f3=0; } else f3=0; } } if(f1&&!f2&&!f3) printf("queue\n"); else if(!f1&&f2&&!f3) printf("priority queue\n"); else if(!f1&&!f2&&f3) printf("stack\n"); else if(!f1&&!f2&&!f3) printf("impossible\n"); else printf("not sure\n"); } }
相关文章推荐
- ZOJ 2747 Windows Message Queue
- 约束,在ios8 没问题,在ios7崩溃的问题,UItextField
- 利用UIScrollView实现几个页面的切换
- UICollectionView简介
- Android Bluetooth4.0(BLE是Bluetooth Low Energy的简称) 官方API
- 限制UITextView中的字数
- ugui脚本添加button相应事件
- UIAlertView使用全解
- Implement Queue using Stacks
- Android UI设计——布局方法
- UITextFiled
- 学习 easyui 之一:easyloader 分析与使用
- Easyui-Datagrid—表头灵活拖动
- uigrid.reposition 多个ITEM不会重叠
- Java中String、StringBuilder和StringBuffer类的区别
- 有关apue.h头文件的疑问???
- UITextField 限制输入长度
- Android 解决非UI线程操作UI的两种办法 :Handler 和 AsynTask
- UILabel
- UILabel添加点击事件