fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class MyQueue {
  6. int[] storage = new int[100000];
  7. int start;
  8. int finish;
  9. MyQueue() {
  10. start = 0;
  11. finish = 0;
  12. }
  13. void push(int n) {
  14. storage[finish] = n;
  15. finish++;
  16. }
  17. int pop() {
  18. int a = storage[start];
  19. start++;
  20. return a;
  21. }
  22. int front() {
  23. return storage[start];
  24. }
  25. int size() {
  26. return finish - start;
  27. }
  28.  
  29. String clear() {
  30. finish = 0;
  31. start = 0;
  32. return "ok";
  33. }
  34.  
  35. String exit() {
  36. return "bye";
  37. }
  38. }
  39.  
  40. public class Main {
  41. public static void main(String[] args) throws java.lang.Exception {
  42. String a;
  43. MyQueue x = new MyQueue();
  44. try (Scanner sc = new Scanner(System.in)) {
  45. while (sc.hasNextLine()){
  46. a = sc.next();
  47. if (a.equals("push")) {
  48. int n;
  49. n = sc.nextInt();
  50. x.push(n);
  51. System.out.println("ok");
  52. }
  53. if (a.equals("pop")) {
  54. System.out.println(x.pop());
  55. }
  56. if (a.equals("front")) {
  57. System.out.println(x.front());
  58. }
  59. if (a.equals("size")) {
  60. System.out.println(x.size());
  61. }
  62. if (a.equals("clear")) {
  63. System.out.println(x.clear());
  64. }
  65. if (a.equals("exit")) {
  66. System.out.println(x.exit());
  67. break;
  68. }
  69. }
  70. }
  71. }
  72. }
Success #stdin #stdout 0.16s 321344KB
stdin
push 123
size
push -5
pop
exit
stdout
ok
1
ok
123
bye