Advertisement
CR7CR7

taskTwo

Aug 31st, 2023
734
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.39 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4. public class LiftTourist {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.  
  8.         int maxLiftCapacity = 4;
  9.         int peopleWaiting = Integer.parseInt(scanner.nextLine());
  10.         int[] numbers = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
  11.  
  12.         for (int wagon = 0; wagon < numbers.length; wagon++) {
  13.             while (numbers[wagon] < maxLiftCapacity && peopleWaiting > 0) {
  14.                 numbers[wagon]++;
  15.                 peopleWaiting--;
  16.             }
  17.         }
  18.  
  19.         if (peopleWaiting == 0 && isEmptySeats(numbers)) {
  20.             System.out.println("The lift has empty spots!");
  21.             printWagons(numbers);
  22.         } else if (peopleWaiting > 0 && !isEmptySeats(numbers)) {
  23.             System.out.println("There isn't enough space! " + peopleWaiting + " people in a queue!");
  24.             printWagons(numbers);
  25.         } else {
  26.             printWagons(numbers);
  27.         }
  28.     }
  29.  
  30.     public static boolean isEmptySeats(int[] numbers) {
  31.         for (int num : numbers) {
  32.             if (num < 4) {
  33.                 return true;
  34.             }
  35.         }
  36.         return false;
  37.     }
  38.  
  39.     public static void printWagons(int[] numbers) {
  40.         for (int num : numbers) {
  41.             System.out.print(num + " ");
  42.         }
  43.     }
  44. }
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement