Mahmoud_Hawara

Untitled

Jul 19th, 2022
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.53 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  4. const long long MOD = 1e9 + 7, OO = 1e18;
  5. const double PI = acos(-1);
  6. const int N = 1e6 + 5;
  7. const int dx[4] = {0, 0, 1, -1};
  8. const int dy[4] = {1, -1, 0, 0};
  9.  
  10. long long t, x;
  11. bool f;
  12. string s;
  13. deque<long long>dq;
  14.  
  15. int main()
  16. {
  17.     IO
  18.     cin >> t;
  19.     while (t--)
  20.     {
  21.         cin >> s;
  22.         if (s[0] == 't')
  23.         {
  24.             cin >> x;
  25.             if (f == 0)dq.push_front(x);
  26.             else dq.push_back(x);
  27.         }
  28.         else if (s[0] == 'p')
  29.         {
  30.             cin >> x;
  31.             if (f == 0)dq.push_back(x);
  32.             else dq.push_front(x);
  33.         }
  34.         else if (s[0] == 'r')
  35.         {
  36.             // f = !f;
  37.             // f = 1 - f;
  38.             f ^= 1;
  39.         }
  40.         else if (dq.empty())
  41.         {
  42.             cout << "No job for Ada?\n";
  43.         }
  44.         else if (s[0] == 'f')
  45.         {
  46.             if (f == 0)
  47.             {
  48.                 cout << dq.front() << '\n';
  49.                 dq.pop_front();
  50.             }
  51.             else
  52.             {
  53.                 cout << dq.back() << '\n';
  54.                 dq.pop_back();
  55.             }
  56.         }
  57.         else
  58.         {
  59.             if (f)
  60.             {
  61.                 cout << dq.front() << '\n';
  62.                 dq.pop_front();
  63.             }
  64.             else
  65.             {
  66.                 cout << dq.back() << '\n';
  67.                 dq.pop_back();
  68.             }
  69.         }
  70.     }
  71.     return 0;
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment