fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4. int n,a,b;
  5. int q,s,p;
  6. while(cin>>n){
  7. queue<int> Q;
  8. stack<int> S;
  9. priority_queue<int> P;
  10. q=1;
  11. s=2;
  12. p=3;
  13. while(n--){
  14. cin>>a>>b;
  15. if(a==1){
  16. Q.push(b);
  17. S.push(b);
  18. P.push(b);
  19. }
  20. else if(a==2){
  21. if(!Q.empty()&&Q.front()==b)Q.pop();
  22. else q=0;
  23. if(!S.empty()&&S.top()==b)S.pop();
  24. else s=0;
  25. if(!P.empty()&&P.top()==b)P.pop();
  26. else p=0;
  27. }
  28. }
  29. int ans=max( max(q,p) , s);
  30. if(!ans)cout<<"impossible"<<endl;
  31. else if((q&&p)||(q&&s)||(s&&p)||(q&&p&&s))cout<<"not sure"<<endl;
  32. else if(q)cout<<"queue"<<endl;
  33. else if(s)cout<<"stack"<<endl;
  34. else if(p)cout<<"priority queue"<<endl;
  35. }
  36. return 0;
  37. }
Success #stdin #stdout 0s 15240KB
stdin
6
1 1
1 2
1 3
2 1
2 2
2 3
6
1 1
1 2
1 3
2 3
2 2
2 1
2
1 1
2 2
4
1 2
1 1
2 1
2 2
7
1 2
1 5
1 1
1 3
2 5
1 4
2
stdout
queue
not sure
impossible
stack
priority queue