Advertisement
Guest User

sla

a guest
Sep 20th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main(){
  6.     int n, x, y;
  7.     stack<int> s;
  8.     queue<int> q;
  9.     priority_queue<int> pq;
  10.     int isq = 1, iss = 1, ispq = 1;
  11.    
  12.     while(cin >> n){
  13.         isq = 1; iss = 1; ispq = 1;
  14.         while(n--){
  15.             cin >> x >> y;
  16.             if(x){
  17.                 s.push(y);
  18.                 q.push(y);
  19.                 pq.push(y);
  20.             }else if(x == 2){
  21.                 if(s.top() != y) iss = 0;
  22.                 if(q.front() != y) isq = 0;
  23.                 if(pq.top() != y) ispq = 0;
  24.                
  25.                 s.pop();
  26.                 q.pop();
  27.                 pq.pop();
  28.             }
  29.         }
  30.         if(!isq && !iss && !ispq) cout << "impossible" << endl;
  31.         else if((isq+iss-1) || (isq+ispq-1) || (iss+ispq-1)) cout << "not sure" << endl;
  32.         else if(isq) cout << "queue" << endl;
  33.         else if(iss) cout << "stack" << endl;
  34.         else if(ispq) cout << "priority queue" << endl;
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement