Advertisement
Saleh127

Light oj(LO) 1212

Apr 13th, 2021
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);cout.tie(0);
  9.  
  10.  
  11. test
  12. {
  13.  
  14.  
  15. string a;
  16. deque<ll>q;
  17.  
  18. ll n,m,i,j,k,l;
  19.  
  20. cin>>n>>m;
  21.  
  22. cout<<"Case "<<cs<<":"<<endl;
  23.  
  24. while(m--)
  25. {
  26. cin>>a;
  27. if((a=="pushLeft" || a=="pushRight") && q.size()>=n)
  28. {
  29. cin>>k;
  30. cout<<"The queue is full"<<endl;
  31. }
  32. else if((a=="popLeft" || a=="popRight") && q.size()==0)
  33. {
  34. cout<<"The queue is empty"<<endl;
  35. }
  36. else if(a=="pushLeft")
  37. {
  38. cin>>k;
  39. q.push_front(k);
  40. cout<<"Pushed in left: "<<k<<endl;
  41. }
  42. else if(a=="pushRight")
  43. {
  44. cin>>k;
  45. q.push_back(k);
  46. cout<<"Pushed in right: "<<k<<endl;
  47. }
  48. else if(a=="popLeft")
  49. {
  50. k=q.front();
  51. cout<<"Popped from left: "<<k<<endl;
  52. q.pop_front();
  53. }
  54. else if(a=="popRight")
  55. {
  56. k=q.back();
  57. cout<<"Popped from right: "<<k<<endl;
  58. q.pop_back();
  59. }
  60. }
  61. }
  62.  
  63. return 0;
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement