Advertisement
beinsaduno

E02TheLift

Feb 20th, 2021
874
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.List;
  3. import java.util.Scanner;
  4. import java.util.stream.Collectors;
  5.  
  6. public class E02TheLIft {
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.         int people = Integer.parseInt(scanner.nextLine());
  11.  
  12.         List<Integer> list = Arrays.stream(scanner.nextLine().trim().split("\\s+"))
  13.                 .map(Integer::parseInt)
  14.                 .collect(Collectors.toList());
  15.  
  16.         for (int i = 0; i < list.size(); i++) {
  17.             if (people < 1) {
  18.                 break;
  19.             }
  20.             while (list.get(i) < 4) {
  21.                 if (people < 1) {
  22.                     break;
  23.                 } else {
  24.                     list.set(i, list.get(i) + 1);
  25.                     people--;
  26.                 }
  27.             }
  28.         }
  29.         if (people < 1) {
  30.             System.out.println("The lift has empty spots!");
  31.         } else {
  32.             System.out.printf("There isn't enough space! %d people in a queue!%n", people);
  33.         }
  34.         System.out.println(list.toString().replaceAll("[\\[\\],]", ""));
  35.     }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement