Advertisement
Korotkodul

2_С

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