Advertisement
lelbaba

C

Mar 19th, 2020
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int t,i;
  6. cin>>t;
  7. for(i=1;i<=t;i++)
  8. {
  9. int n,m,j,k,l,x,s,y;
  10. vector < pair<int,int> > v;
  11. deque <int> q;
  12. string st,sk;
  13. cin>>n>>m;
  14. j=0;
  15. l=m;
  16. while(l--)
  17. {
  18. cin>>st;
  19. if(st=="pushLeft")
  20. {
  21. cin>>x;
  22. j++;
  23. if(j>n)
  24. {
  25. j=n;
  26. v.push_back(make_pair(5,0));
  27. }
  28. else
  29. {
  30. q.push_front(x);
  31. v.push_back(make_pair(1,x));
  32. }
  33. }
  34. else if(st=="pushRight")
  35. {
  36. cin>>x;
  37. j++;
  38. if(j>n)
  39. {
  40. j=n;
  41. v.push_back(make_pair(5,0));
  42. }
  43. else
  44. {
  45. q.push_back(x);
  46. v.push_back(make_pair(2,x));
  47. }
  48. }
  49. else if(st=="popLeft")
  50. {
  51. j--;
  52. if(j<0)
  53. {
  54. j=0;
  55. v.push_back(make_pair(0,0));
  56. }
  57. else
  58. {
  59. x=q[0];
  60. q.pop_front();
  61. v.push_back(make_pair(3,x));
  62. }
  63. }
  64.  
  65. else if(st=="popRight")
  66. {
  67. j--;
  68. if(j<0)
  69. {
  70. j=0;
  71. q.pop_back();
  72. v.push_back(make_pair(0,0));
  73. }
  74. else
  75. {
  76. x=q[q.size()-1];
  77. v.push_back(make_pair(4,x));
  78. }
  79. }
  80. }
  81. cout<<"Case "<<i<<":"<<endl;
  82. for(int k=0;k<m;k++)
  83. {
  84. if(v[k].first==0) cout<<"The queue is empty"<<endl;
  85. else if(v[k].first==5) cout<<"The queue is full"<<endl;
  86. else if(v[k].first==1) cout<<"Pushed in left: "<<v[k].second<<endl;
  87. else if(v[k].first==2) cout<<"Pushed in right: "<<v[k].second<<endl;
  88. else if(v[k].first==3) cout<<"Popped from left: "<<v[k].second<<endl;
  89. else if(v[k].first==4) cout<<"Popped from right: "<<v[k].second<<endl;
  90. }
  91.  
  92. }
  93. return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement