Advertisement
Korotkodul

2_D_WA2

Oct 24th, 2023 (edited)
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. #include <cmath>
  2. #include <iostream>
  3. #include <stack>
  4. #include <vector>
  5.  
  6. using std::cin;
  7. using std::cout;
  8. using std::max;
  9. using std::min;
  10. using std::stack;
  11. using std::string;
  12. using std::vector;
  13.  
  14. int main() {
  15.   /*std::ios::sync_with_stdio(false);
  16.   std::cin.tie(0);
  17.   std::cout.tie(0);*/
  18.   stack<int> orig;
  19.   stack<int> mini;
  20.   int cmd;
  21.   cin >> cmd;
  22.   string req;
  23.   int cnt = 0;
  24.   for (int go = 0; go < cmd; ++go) {
  25.     cin >> req;
  26.     if (req == "enqueue") {
  27.       cnt++;
  28.       int num;
  29.       cin >> num;
  30.       int tomin = num;
  31.       if (!mini.empty()) {
  32.         tomin = min(mini.top(), num);
  33.       }
  34.       orig.push(num);
  35.       mini.push(tomin);
  36.       cout << "ok\n";
  37.     } else if (req == "front") {
  38.       if (cnt == 0) {
  39.         cout << "error\n";
  40.         continue;
  41.       }
  42.       cout << orig.top() << "\n";
  43.     } else if (req == "clear") {
  44.       while (cnt > 0) {
  45.         cnt--;
  46.         orig.pop();
  47.         mini.pop();
  48.       }
  49.       cout << "ok\n";
  50.     } else if (req == "size") {
  51.       cout << cnt << "\n";
  52.     } else if (req == "min") {
  53.       if (cnt == 0) {
  54.         cout << "error\n";
  55.         continue;
  56.       }
  57.       cout << mini.top() << "\n";
  58.     } else if (req == "dequeue") {
  59.       if (cnt == 0) {
  60.         cout << "error\n";
  61.         continue;
  62.       }
  63.       cnt--;
  64.       cout << orig.top() << "\n";
  65.       orig.pop();
  66.       mini.pop();
  67.     }
  68.   }
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement