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.front()!=b)q=0;
  22. else Q.pop();
  23. if(S.top()!=b)s=0;
  24. else S.pop();
  25. if(P.top()!=b)p=0;
  26. else P.pop();
  27. }
  28. cout<<q<<" "<<p<<" "<<s<<endl;
  29.  
  30. }
  31. int ans=max( max(q,p) , s);
  32. if(!ans)cout<<"impossible"<<endl;
  33. else if((q&&p)||(q&&s)||(s&&p)||(q&&p&&s))cout<<"not sure"<<endl;
  34. else if(q)cout<<"queue"<<endl;
  35. else if(s)cout<<"stack"<<endl;
  36. else if(p)cout<<"priority queue"<<endl;
  37. }
  38. return 0;
  39. }
Success #stdin #stdout 0s 15240KB
stdin
6
1 1
1 2
1 3
2 3
2 2
2 1
2
1 1
2 2
stdout
1 3 2
1 3 2
1 3 2
0 3 2
0 3 2
0 3 2
not sure
1 3 2
0 0 0
impossible