Advertisement
Korotkodul

2_C

Oct 22nd, 2023 (edited)
806
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.22 KB | None | 0 0
  1. #include <cmath>
  2. #include <deque>
  3. #include <iostream>
  4. #include <vector>
  5.  
  6.  
  7. using std::cin;
  8. using std::cout;
  9. using std::max;
  10. using std::min;
  11. using std::string;
  12. using std::vector;
  13. using std::deque;
  14.  
  15. int main() {
  16.   std::ios::sync_with_stdio(false);
  17.   std::cin.tie(0);
  18.   std::cout.tie(0);
  19.   deque<int> qa;
  20.   deque<int> qb;
  21.   int qur;
  22.   cin >> qur;
  23.   int cnt1 = 0;
  24.   int cnt2 = 0;
  25.   int num = 0;
  26.   for (int step = 0; step < qur; ++step) {
  27.     char type;
  28.     cin >> type;
  29.     int nmb;
  30.     if (type == '+') {
  31.       cin >> nmb;
  32.       if (cnt1 == num) {
  33.         qa.push_back(qb.front());
  34.         qb.pop_front();
  35.         qb.push_back(nmb);
  36.         cnt1++;
  37.       } else {
  38.         num++;
  39.         cnt2++;
  40.         qb.push_back(nmb);
  41.       }
  42.     } else if (type == '*') {
  43.       cin >> nmb;
  44.       if (cnt1 == num) {
  45.         qa.push_back(nmb);
  46.         cnt1++;
  47.       } else {
  48.         cnt2++;
  49.         num++;
  50.         qb.push_front(nmb);
  51.       }
  52.     } else {
  53.       int res = qa.front();
  54.       cout << res << "\n";
  55.       if (cnt1 == num + 1) {
  56.         cnt1--;
  57.       } else {
  58.         int go = qb.front();
  59.         qa.push_back(go);
  60.         qb.pop_front();
  61.         num--;
  62.         cnt2--;
  63.       }
  64.     }
  65.   }
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement