Advertisement
damesova

Hot Potato [Mimi][JA]

May 19th, 2019
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.74 KB | None | 0 0
  1. import java.util.ArrayDeque;
  2. import java.util.Arrays;
  3. import java.util.Scanner;
  4. import java.util.stream.Collectors;
  5.  
  6. public class _06_HotPotato {
  7.     public static void main(String[] args) {
  8.         Scanner sc = new Scanner(System.in);
  9.  
  10.         ArrayDeque<String> q = Arrays
  11.                 .stream(sc.nextLine()
  12.                         .split("\\s+"))
  13.                 .collect(Collectors.toCollection(ArrayDeque::new));
  14.  
  15.         int position = Integer.parseInt(sc.nextLine());
  16.  
  17.         while (q.size() > 1) {
  18.             for (int i = 1; i < position; i++) {
  19.                 q.offer(q.poll());
  20.             }
  21.             System.out.println("Removed " + q.poll());
  22.         }
  23.  
  24.         System.out.println("Last is " + q.poll());
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement