Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Scanner;
- public class LiftTourist {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int maxLiftCapacity = 4;
- int peopleWaiting = Integer.parseInt(scanner.nextLine());
- int[] numbers = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
- for (int wagon = 0; wagon < numbers.length; wagon++) {
- while (numbers[wagon] < maxLiftCapacity && peopleWaiting > 0) {
- numbers[wagon]++;
- peopleWaiting--;
- }
- }
- if (peopleWaiting == 0 && isEmptySeats(numbers)) {
- System.out.println("The lift has empty spots!");
- printWagons(numbers);
- } else if (peopleWaiting > 0 && !isEmptySeats(numbers)) {
- System.out.println("There isn't enough space! " + peopleWaiting + " people in a queue!");
- printWagons(numbers);
- } else {
- printWagons(numbers);
- }
- }
- public static boolean isEmptySeats(int[] numbers) {
- for (int num : numbers) {
- if (num < 4) {
- return true;
- }
- }
- return false;
- }
- public static void printWagons(int[] numbers) {
- for (int num : numbers) {
- System.out.print(num + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement