Advertisement
chevengur

Вводный курс: основы C++ | Урок 4: Меняем размер вектора 1/2

Aug 28th, 2023 (edited)
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8.     int q;
  9.     cin >> q;
  10.  
  11.     vector<bool>queue;
  12.  
  13.     for (int i = 0; i < q; ++i) {
  14.         string operation_code;
  15.         cin >> operation_code;
  16.  
  17.         if (operation_code == "WORRY"s) {
  18.             int index;
  19.             cin >> index;
  20.             queue[index] = true;
  21.         }
  22.  
  23.         else if (operation_code == "HAPPY"s) {
  24.             int index;
  25.             cin >> index;
  26.             queue[index] = false;
  27.         }
  28.  
  29.         else if (operation_code == "COME"s) {
  30.             int count;
  31.             cin >> count;
  32.             queue.resize(queue.size()+count, false);
  33.         }
  34.  
  35.         else if (operation_code == "LAST_WORRY"s) {
  36.             if (!queue.empty()) {
  37.                 if (queue.back() == true) {
  38.                     cout << "worry" << endl;
  39.                 }
  40.                 else if (queue.back() == false) {
  41.                     cout << "happy" << endl;
  42.                 }
  43.             }
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement