fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define MM ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
  4. int main(){
  5. MM
  6. int t,f=1;
  7. cin>>t;
  8. deque<int> ss;
  9. bool flag = false;
  10. while (t--) {
  11. string s;
  12. cin>>s;
  13. if (s=="toFront") {
  14. int n;
  15. cin>>n;
  16. if (flag) {
  17. ss.push_back(n);
  18. }
  19. else {
  20. ss.push_front(n);
  21. }
  22. }
  23. else if (s=="push_back") {
  24. int n;
  25. cin>>n;
  26. if (flag) {
  27. ss.push_front(n);
  28. }
  29. else {
  30. ss.push_back(n);
  31. }
  32. }
  33. else if (s=="back") {
  34. if (!ss.empty()) {
  35. cout<<ss.back()<<'\n';
  36. ss.pop_back();
  37. }
  38. else {
  39. cout<<"No job for Ada?"<<'\n';
  40. }
  41. }
  42. else if (s=="front") {
  43. if (!ss.empty()) {
  44. cout<<ss.front()<<'\n';
  45. ss.pop_front();
  46. }
  47. else {
  48. cout<<"No job for Ada?"<<'\n';
  49. }
  50. }
  51. else if (s=="reverse") {
  52. if (f) {
  53. flag = true;
  54. f=0;
  55. }
  56. else {
  57. flag = false;
  58. f=1;
  59. }
  60. }
  61. }
  62. }
Success #stdin #stdout 0.01s 5276KB
stdin
15
toFront 93
front
back
reverse
back
reverse
toFront 80
push_back 53
push_back 50
front
front
reverse
push_back 66
reverse
front
stdout
93
No job for Ada?
No job for Ada?
80
53
66