您的位置:首页 > 产品设计 > UI/UE

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");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: