RGAlex

O2. The Lift / O1. Mid Exam Retake

Feb 11th, 2021 (edited)
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. package MidExam.O1;
  2.  
  3.  
  4. import java.util.Arrays;
  5. import java.util.Scanner;
  6.  
  7. public class O2TheLift {
  8.     public static void main(String[] args) {
  9.         Scanner scanner = new Scanner(System.in);
  10.         int people = Integer.parseInt(scanner.nextLine());
  11.         int[] liftPlace = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
  12.         for (int i = 0; i < liftPlace.length; i++) {
  13.             while (liftPlace[i] < 4) {
  14.                 liftPlace[i] += 1;
  15.                 people -= 1;
  16.                 if (people == 0) {
  17.                     break;
  18.                 }
  19.             }
  20.             if (people == 0) {
  21.                 break;
  22.             }
  23.         }
  24.         if (people == 0 && liftPlace[liftPlace.length - 1] < 4) {
  25.             System.out.println("The lift has empty spots!");
  26.         } else if (people > 0){
  27.             System.out.printf("There isn't enough space! %d people in a queue!%n", people);
  28.         }
  29.         for (int peopleOnSeats : liftPlace) {
  30.             System.out.print(peopleOnSeats + " ");
  31.         }
  32.     }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment