Advertisement
vov44k

59

Nov 27th, 2022
883
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.28 KB | None | 0 0
  1. import javax.management.Query;
  2. import java.io.*;
  3. import java.util.*;
  4.  
  5. public class Main {
  6.     public static void main(String[] args) throws FileNotFoundException {
  7.         Scanner in = new Scanner(new File("input.txt"));
  8.         PrintWriter pw = new PrintWriter("output.txt");
  9.  
  10.         Queue<Integer> queue = new LinkedList<>();
  11.         String a;
  12.         do {
  13.             a = in.next();
  14.  
  15.             switch (a) {
  16.                 case "push":
  17.                     queue.add(in.nextInt());
  18.                     pw.println("ok");
  19.                     break;
  20.                 case "pop":
  21.                     if (queue.size() == 0) pw.println("error");
  22.                     else pw.println(queue.poll());
  23.                     break;
  24.  
  25.                 case "front":
  26.                     if (queue.size() == 0) pw.println("error");
  27.                     else pw.println(queue.peek());
  28.                     break;
  29.  
  30.                 case "size":
  31.                     pw.println(queue.size());
  32.                     break;
  33.                 case "clear":
  34.                     queue.clear();
  35.                     pw.println("ok");
  36.                     break;
  37.             }
  38.         } while (!a.equals("exit"));
  39.  
  40.         pw.println("bye");
  41.  
  42.  
  43.         in.close();
  44.         pw.close();
  45.  
  46.  
  47.     }
  48.  
  49.  
  50.    
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement