fork download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4. bool daonguoc=false;
  5. string s;
  6. deque<int> q;
  7. void add_front()
  8. {
  9. int k;
  10. cin>>k;
  11. if(!daonguoc) q.push_front(k);
  12. else q.push_back(k);
  13. }
  14. void in_xoa()
  15. {
  16. if(!daonguoc) if(q.empty()) cout<<"No job for Ada?"<<endl;
  17. else
  18. {
  19. cout<<q.front()<<endl;
  20. q.pop_front();
  21. }
  22. else
  23. {
  24. if(q.empty()) cout<<"No job for Ada?"<<endl;
  25. else {
  26. cout<<q.back()<<endl;
  27. q.pop_back();
  28. }
  29. }
  30. }
  31. void incuoi_xoa()
  32. {
  33. if(daonguoc) if(q.empty()) cout<<"No job for Ada?"<<endl;
  34. else
  35. {
  36. cout<<q.front()<<endl;
  37. q.pop_front();
  38. }
  39. else
  40. {
  41. if(q.empty()) cout<<"No job for Ada?"<<endl;
  42. else
  43. {
  44. cout<<q.back()<<endl;
  45. q.pop_back();
  46. }
  47. }
  48. }
  49. void pb()
  50. {
  51. int k;cin>>k;
  52. if(daonguoc)q.push_front(k);
  53. else q.push_back(k);
  54. }
  55. int main()
  56. {
  57. std::ios::sync_with_stdio(false);
  58. int t;
  59. cin>>t;
  60. while(t-->0)
  61. {
  62. cin>>s;
  63. if(s=="toFront")add_front();
  64. else if(s=="front") in_xoa();
  65. else if(s=="back")incuoi_xoa();
  66. else if(s=="reverse") daonguoc=not daonguoc;
  67. else if(s=="push_back") pb();
  68. }
  69. return 0;
  70. }
  71.  
Success #stdin #stdout 0s 4548KB
stdin
Standard input is empty
stdout
Standard output is empty