Riposati

Untitled

May 16th, 2019
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <stack>
  4. #include <queue>
  5. using namespace std;
  6.  
  7. int main() {
  8.         int n, op, x;
  9.         while (scanf("%d", &n) != EOF) {
  10.                 queue<int> q;
  11.                 stack<int> s;
  12.                 priority_queue<int> pq;
  13.                 bool isS = true, isQ = true, isPQ = true;
  14.  
  15.                 for (int i = 0; i < n; i++) {
  16.                         scanf("%d %d", &op, &x);
  17.  
  18.                         switch (op) {
  19.                         case 1:
  20.                                 if (isS)
  21.                                         s.push(x);
  22.                                 if (isQ)
  23.                                         q.push(x);
  24.                                 if (isPQ)
  25.                                         pq.push(x);
  26.                                 break;
  27.                         case 2:
  28.                                 if (isS) {
  29.                                         if (s.empty() || s.top() != x)
  30.                                                 isS = false;
  31.                                         else
  32.                                                 s.pop();
  33.                                 }
  34.                                 if (isQ) {
  35.                                         if (q.empty() || q.front() != x)
  36.                                                 isQ = false;
  37.                                         else
  38.                                                 q.pop();
  39.                                 }
  40.                                 if (isPQ) {
  41.                                         if (pq.empty() || pq.top() != x)
  42.                                                 isPQ = false;
  43.                                         else
  44.                                                 pq.pop();
  45.                                 }
  46.                                 break;
  47.                         }
  48.                 }
  49.  
  50.                 if (isS == true && isQ == false && isPQ == false)
  51.                         cout << "stack" << endl;
  52.                 else if (isS == false && isQ == true && isPQ == false)
  53.                         cout << "queue" << endl;
  54.                 else if (isS == false && isQ == false && isPQ == true)
  55.                         cout << "priority queue" << endl;
  56.                 else if (isS == false && isQ == false && isPQ == false)
  57.                         cout << "impossible" << endl;
  58.                 else
  59.                         cout << "not sure" << endl;
  60.         }
  61. }
Add Comment
Please, Sign In to add comment