#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,j,i,a,b;
int cs,cq,cpq;
while(cin>>n)
{
priority_queue <int> pq;
stack <int>s;
queue<int>q;
cs=cq=cpq=1;
bool im=false;
for(i=1; i<=n; i++)
{
cin>>a>>b;
if(a==1)
{
q.push(b);
s.push(b);
pq.push(b);
}
if(a==2)
{
//cout<<"b="<<b<<" "<<s.top()<<endl;
if(s.empty() || q.empty() || pq.empty())
im=true;
else
{
if(b!=s.top())
{
cs=0;
}
if(b!=q.front())
{
cq=0;
}
if(b!=pq.top())
{
cpq=0;
}
q.pop();
pq.pop();
s.pop();
}
}
}
//cout<<cs<<" "<<cq<<" "<<cpq<<endl;
if(im)
cout<<"impossible"<<endl;
else if(cs+cq+cpq>1)
cout<<"not sure"<<endl;
else if(cs==1&&cq==0&&cpq==0)
cout<<"stack"<<endl;
else if(cs==0&&cq==1&&cpq==0)
cout<<"queue"<<endl;
else if(cs==0&&cq==0&&cpq==1)
cout<<"priority queue"<<endl;
else
cout<<"impossible"<<endl;
}
return 0;
}
using namespace std;
int main()
{
int n,j,i,a,b;
int cs,cq,cpq;
while(cin>>n)
{
priority_queue <int> pq;
stack <int>s;
queue<int>q;
cs=cq=cpq=1;
bool im=false;
for(i=1; i<=n; i++)
{
cin>>a>>b;
if(a==1)
{
q.push(b);
s.push(b);
pq.push(b);
}
if(a==2)
{
//cout<<"b="<<b<<" "<<s.top()<<endl;
if(s.empty() || q.empty() || pq.empty())
im=true;
else
{
if(b!=s.top())
{
cs=0;
}
if(b!=q.front())
{
cq=0;
}
if(b!=pq.top())
{
cpq=0;
}
q.pop();
pq.pop();
s.pop();
}
}
}
//cout<<cs<<" "<<cq<<" "<<cpq<<endl;
if(im)
cout<<"impossible"<<endl;
else if(cs+cq+cpq>1)
cout<<"not sure"<<endl;
else if(cs==1&&cq==0&&cpq==0)
cout<<"stack"<<endl;
else if(cs==0&&cq==1&&cpq==0)
cout<<"queue"<<endl;
else if(cs==0&&cq==0&&cpq==1)
cout<<"priority queue"<<endl;
else
cout<<"impossible"<<endl;
}
return 0;
}
No comments:
Post a Comment