Advertisement
Ligh7_of_H3av3n

TheLift

Feb 14th, 2024
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.48 KB | None | 0 0
  1. package Lekcii;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class TheLift {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         int people = Integer.parseInt(scanner.nextLine());
  10.         String[] wagonsStr = scanner.nextLine().split(" ");
  11.         int[] wagons = new int[wagonsStr.length];
  12.  
  13.         for (int i = 0; i < wagons.length; i++) {
  14.             wagons[i] = Integer.parseInt(wagonsStr[i]);
  15.         }
  16.  
  17.         for (int i = 0; i < wagons.length; i++) {
  18.             while (wagons[i] < 4 && people > 0) {
  19.                 wagons[i]++;
  20.                 people--;
  21.             }
  22.         }
  23.  
  24.         boolean hasEmptySpots = false;
  25.         boolean notEnoughSpace = false;
  26.  
  27.         for (int wagon : wagons) {
  28.             if (wagon < 4) {
  29.                 hasEmptySpots = true;
  30.                 break;
  31.             }
  32.         }
  33.  
  34.         if (people == 0 && hasEmptySpots) {
  35.             System.out.println("The lift has empty spots!");
  36.         } else if (people > 0 && !hasEmptySpots) {
  37.             notEnoughSpace = true;
  38.             System.out.printf("There isn't enough space! %d people in a queue!%n", people);
  39.         }
  40.  
  41.         for (int i = 0; i < wagons.length; i++) {
  42.             System.out.print(wagons[i]);
  43.             if (i != wagons.length - 1) {
  44.                 System.out.print(" ");
  45.             }
  46.         }
  47.  
  48.         if (!notEnoughSpace) {
  49.             System.out.println();
  50.         }
  51.  
  52.         scanner.close();
  53.     }
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement