Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package MidExam.O1;
- import java.util.Arrays;
- import java.util.Scanner;
- public class O2TheLift {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int people = Integer.parseInt(scanner.nextLine());
- int[] liftPlace = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
- for (int i = 0; i < liftPlace.length; i++) {
- while (liftPlace[i] < 4) {
- liftPlace[i] += 1;
- people -= 1;
- if (people == 0) {
- break;
- }
- }
- if (people == 0) {
- break;
- }
- }
- if (people == 0 && liftPlace[liftPlace.length - 1] < 4) {
- System.out.println("The lift has empty spots!");
- } else if (people > 0){
- System.out.printf("There isn't enough space! %d people in a queue!%n", people);
- }
- for (int peopleOnSeats : liftPlace) {
- System.out.print(peopleOnSeats + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment