fork download
  1. import java.util.*;
  2.  
  3. class deque{
  4. private static final int Size = 200000;
  5. int start, end;
  6. int [] folder = new int[Size] ;
  7.  
  8. deque(){
  9. start = end = Size/2;
  10. }
  11. void push_front(int var){
  12. folder[--start] = var;
  13. System.out.println("ok");
  14. }
  15. void push_back(int var){
  16. folder[end++] = var;
  17. System.out.println("ok");
  18. }
  19. void pop_front(){
  20. System.out.println(folder[start++]);
  21. }
  22. void pop_back(){
  23. System.out.println(folder[--end]);
  24. }
  25. void front(){
  26. System.out.println(folder[start]);
  27. }
  28. void back(){
  29. System.out.println(folder[end-1]);
  30. }
  31. void size(){
  32. System.out.println(end-start);
  33. }
  34. void clear(){
  35. start = end = Size/2;
  36. System.out.println("ok");
  37. }
  38. };
  39.  
  40. class Main
  41. {
  42. public static void main (String[] args) throws java.lang.Exception
  43. {
  44. Scanner scan = new Scanner(System.in);
  45. deque deq = new deque();
  46. String S;
  47.  
  48. while (scan.hasNext()){
  49. S = scan.next();
  50. if (S.equals("push_front")) deq.push_front(scan.nextInt());
  51. else if (S.equals("push_back")) deq.push_back(scan.nextInt());
  52. else if (S.equals("pop_front")) deq.pop_front();
  53. else if (S.equals("pop_back")) deq.pop_back();
  54. else if (S.equals("front")) deq.front();
  55. else if (S.equals("back")) deq.back();
  56. else if (S.equals("size")) deq.size();
  57. else if (S.equals("clear")) deq.clear();
  58. else if (S.equals("exit")){
  59. System.out.println("bye");
  60. System.exit(0);
  61. }
  62. }
  63. }
  64. }
Success #stdin #stdout 0.07s 4706304KB
stdin
push_back 3
push_front 14
size
clear
push_front 1
back
push_back 2
front
pop_back
size
pop_front
size
exit
stdout
ok
ok
2
ok
ok
1
ok
1
2
1
1
0
bye