SHARE
TWEET

randomMagics

a guest May 19th, 2019 69 in 114 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package Advanced.StackAndQueues;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.*;
  7. import java.util.concurrent.atomic.AtomicBoolean;
  8. import java.util.stream.IntStream;
  9.  
  10. public class BasicQueueOperations {
  11.     public static void main(String[] args) throws IOException {
  12.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  13.         ArrayDeque<Integer> queue = new ArrayDeque<>();
  14.         AtomicBoolean isThere = new AtomicBoolean(false);
  15.         int[] params = Arrays.stream(reader.readLine().split("\\s+"))
  16.                 .mapToInt(Integer::parseInt).toArray();
  17.         var ref = new Object() {
  18.             int min = Integer.MAX_VALUE;
  19.         };
  20.         if (params[0] <= params[1]) {
  21.             System.out.println(0);
  22.         } else {
  23.             for (String numb : reader.readLine().split("\\s+")) {
  24.                 queue.offer(Integer.parseInt(numb));
  25.             }
  26.             queue.stream().mapToInt(Integer::intValue).limit(params[0]).skip(params[1])
  27.                     .forEach(x -> {
  28.                         if (x == params[2]) {
  29.                             System.out.println(true);
  30.                             isThere.set(true);
  31.                         } else if (x < ref.min) {
  32.                             ref.min = x;
  33.                         }
  34.                     });
  35.             if (!isThere.get()) {
  36.                 System.out.println(ref.min);
  37.             }
  38.         }  
  39.     }
  40. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top