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