fork(1) download
  1. #include <iostream>
  2. #include <deque>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. int main() {
  8. deque<int>p;
  9. int n;
  10. cin>>n;
  11. while(n--){
  12. string g;
  13. cin>>g;
  14. int o;
  15. if(g=="push_back"){
  16. cin>>o;
  17. p.push_back(o);
  18. }else if(g=="push_front"){
  19. cin>>o;
  20. p.push_front(o);}
  21. else if(g=="print"){
  22. cin>>o;
  23. cout<<p[o]<<endl;
  24. }
  25. else if(g=="pop_back"){
  26. p.pop_back();}
  27. else if(g=="pop_front"){
  28. p.pop_front();}
  29. else if(g=="front"){
  30. cout<<p.front()<<endl;}
  31. else if(g=="back"){
  32. cout<<p.back()<<endl;
  33. }
  34. }
  35. }
Success #stdin #stdout 0.01s 5276KB
stdin
16
push_back 5
front
back
push_back 6
front
back
push_front 3
front
back
print 2
pop_back
front
back
pop_front
front
back
stdout
5
5
5
6
3
6
6
3
5
5
5