Created
February 23, 2016 19:19
-
-
Save nomarlo/e3499c55e50d381b7ed3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
La idea de solucion es hacer una simulacion con las tres estructuras | |
**/ | |
#include <iostream> | |
#include <cstdio> | |
#include <stack> | |
#include <queue> | |
using namespace std; | |
int main(){ | |
int n; | |
int s,q,pq; //para verificar si aun puede ser valida esa estructura de datos | |
int op,num; | |
while(cin>>n){ | |
stack <int> S; | |
queue <int> Q; | |
priority_queue <int> PQ; | |
s=q=pq=1; | |
while(n--){ | |
scanf("%d %d",&op,&num); | |
if(op==1){ | |
if(s) | |
S.push(num); | |
if(q) | |
Q.push(num); | |
if(pq) | |
PQ.push(num); | |
} | |
else{ | |
if(s){ | |
if(S.empty()){ | |
s=0; | |
} | |
else{ | |
if(S.top()!= num) | |
s=0; | |
S.pop(); | |
} | |
} | |
if(q){ | |
if(Q.empty()){ | |
q=0; | |
} | |
else{ | |
if(Q.front()!=num) | |
q=0; | |
Q.pop(); | |
} | |
} | |
if(pq){ | |
if(PQ.empty()){ | |
pq=0; | |
} | |
else{ | |
if(PQ.top()!=num) | |
pq=0; | |
PQ.pop(); | |
} | |
} | |
} | |
} | |
if( (s+q+pq) >1){ | |
printf("not sure\n"); | |
} | |
else if( (s+q+pq) ==0){ | |
printf("impossible\n"); | |
} | |
else if(s){ | |
printf("stack\n"); | |
} | |
else if(q){ | |
printf("queue\n"); | |
} | |
else if(pq){ | |
printf("priority queue\n"); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment