Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayDeque;
- import java.util.Arrays;
- import java.util.Scanner;
- import java.util.stream.Collectors;
- public class _06_HotPotato {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- ArrayDeque<String> q = Arrays
- .stream(sc.nextLine()
- .split("\\s+"))
- .collect(Collectors.toCollection(ArrayDeque::new));
- int position = Integer.parseInt(sc.nextLine());
- while (q.size() > 1) {
- for (int i = 1; i < position; i++) {
- q.offer(q.poll());
- }
- System.out.println("Removed " + q.poll());
- }
- System.out.println("Last is " + q.poll());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement