Advertisement
SotirovG

HotPotato_06/JavaAdvanced

Sep 18th, 2021
927
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. package JavaProModule.JavaAdvanced.StackAndQueuesLab;
  2.  
  3. import java.util.ArrayDeque;
  4. import java.util.Collections;
  5. import java.util.Deque;
  6. import java.util.Scanner;
  7.  
  8. public class HotPotato_06 {
  9.     public static void main(String[] args) {
  10.         Scanner read = new Scanner(System.in);
  11.  
  12.         String [] children = read.nextLine().split("\\s+");
  13.  
  14.         Deque<String> players = new ArrayDeque<>(/*Queue*/);
  15.         Collections.addAll(players,children);
  16.  
  17.         int loop = Integer.parseInt(read.nextLine());
  18.        
  19.         while (players.size() > 1){
  20.             for (int index = 1; index < loop; index++) {
  21.                 players.offer(players.poll());
  22.             }
  23.                 System.out.println("Removed " + players.poll());
  24.         }
  25.             System.out.println("Last is " + players.poll());
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.     }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement