Advertisement
deyanmalinov

4. Basic Queue Operations 2

Mar 24th, 2020
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.96 KB | None | 0 0
  1. package DPM;
  2. import java.util.ArrayDeque;
  3. import java.util.Collections;
  4. import java.util.Scanner;
  5.  
  6. public class Main {
  7.     public static void main(String[] args) {
  8.         Scanner scan = new Scanner(System.in);
  9.         String[] comands = scan.nextLine().split("\\s+");
  10.         String[] line = scan.nextLine().split(" ");
  11.         ArrayDeque<Integer> queue = new ArrayDeque<>();
  12.         for (int i = 0; i < line.length; i++) {
  13.             queue.offer(Integer.parseInt(line[i]));
  14.         }
  15.         int times= Integer.parseInt(comands[1]);
  16.         for (int i = 0; i <times ; i++) {
  17.             queue.poll();
  18.         }
  19.         if (queue.isEmpty()){
  20.             System.out.println(0);
  21.         }else {
  22.             int element = Integer.parseInt(comands[2]);
  23.             if (queue.contains(element)) {
  24.                 System.out.println("true");
  25.             } else {
  26.                 System.out.println(Collections.min(queue));
  27.             }
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement