Advertisement
JosepRivaille

P50709: Col·lecció de números

Feb 18th, 2016
973
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. using namespace std;
  4.  
  5. int main() {
  6.   int n;
  7.   char action;
  8.   priority_queue<int> pq;
  9.   while (cin >> action) {
  10.     switch (action) {
  11.       case 'S':
  12.     cin >> n;
  13.     pq.push(n);
  14.     break;
  15.       case 'A':
  16.     if (pq.empty()) cout << "error!" << endl;
  17.     else cout << pq.top() << endl;
  18.     break;
  19.       case 'R':
  20.     if (pq.empty()) cout << "error!" << endl;
  21.     else pq.pop();
  22.     break;
  23.       case 'I':
  24.     if (pq.empty()) cout << "error!" << endl;
  25.     else {
  26.       int aux = pq.top();
  27.       pq.pop();
  28.       cin >> n;
  29.       aux += n;
  30.       pq.push(aux);
  31.     }
  32.     break;
  33.       case 'D':
  34.     if (pq.empty()) cout << "error!" << endl;
  35.     else {
  36.       int aux = pq.top();
  37.       pq.pop();
  38.       cin >> n;
  39.       aux -= n;
  40.       pq.push(aux);
  41.     }
  42.     break;
  43.       default:
  44.     break;
  45.     }
  46.   }
  47. }
  48.  
  49. //JosepRivaille
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement