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