Advertisement
ShRooK_MoHameD

MyCode

Nov 13th, 2022
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. void solve()
  2.   {
  3.     ll q;
  4.     cin>>q;
  5.     while(q--)
  6.     {
  7.       string s;
  8.       cin>>s;
  9.       deque<int>dq;
  10.       if(s=="toFront")
  11.       {
  12.         int n;
  13.         cin>>n;
  14.         dq.push_front(n);
  15.       }
  16.       else if(s=="push_back")
  17.       {
  18.         int m;
  19.         cin>>m;
  20.         dq.push_back(m);
  21.       }
  22.       else
  23.       {
  24.         if(s=="front"&&!dq.empty())
  25.         {
  26.           cout<<dq.front()<<nl;
  27.           dq.pop_front();
  28.         }
  29.          else if(s=="back"&&!dq.empty())
  30.         {
  31.           cout<<dq.back()<<nl;
  32.           dq.pop_back();
  33.         }
  34.         else if((s=="back"||s=="front")&&dq.empty())
  35.         {
  36.           cout<<"No job for Ada?"<<nl;
  37.         }
  38.          else if(s=="reverse")
  39.         {
  40.            reverse(all(dq));
  41.         }
  42.       }
  43.     }
  44.      
  45.   }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement