jakaria_hossain

lightoj - 1212 - Double Ended Queue

Aug 22nd, 2019
102
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. int main()
  5. {
  6. int test;
  7. cin>>test;
  8. for(int t=1; t<=test; t++)
  9. {
  10. int m,n,x;
  11. cin>>m>>n;
  12. printf("Case %d:\n",t);
  13. deque<int>q;
  14. string s;
  15. while(n--)
  16. {
  17. cin>>s;
  18. if(s=="pushLeft" || s=="pushRight")
  19. {
  20. cin>>x;
  21. if(q.size()==m)
  22. printf("The queue is full\n");
  23. else
  24. {
  25. if(s=="pushLeft")
  26. {
  27. q.push_front(x);
  28. printf("Pushed in left: %d\n",x);
  29. }
  30. else
  31. {
  32. q.push_back(x);
  33. printf("Pushed in right: %d\n",x);
  34. }
  35. }
  36. }
  37. else
  38. {
  39. if(q.size()==0)
  40. {
  41. printf("The queue is empty\n");
  42. }
  43. else
  44. {
  45. if(s=="popLeft")
  46. {
  47. printf("Popped from left: %d\n",q.front());
  48. q.pop_front();
  49. }
  50. else
  51. {
  52. printf("Popped from right: %d\n",q.back());
  53. q.pop_back();
  54. }
  55. }
  56. }
  57. }
  58. }
  59. }
RAW Paste Data