View difference between Paste ID: 4YUFEvzK and 4J2xZ3X2
SHOW: | | - or go back to the newest paste.
1
import java.util.Arrays;
2
import java.util.List;
3
import java.util.Scanner;
4
import java.util.stream.Collectors;
5
6
public class TheLift_02 {
7
    public static void main(String[] args) {
8
        Scanner scanner = new Scanner(System.in);
9
10
        int people = Integer.parseInt(scanner.nextLine());
11
        boolean noMorePeople = false;
12
13
        List<Integer> lift = Arrays.stream(scanner.nextLine().split("\\s+")).
14
                map(Integer::parseInt).collect(Collectors.toList());
15
16
        for (int cabin = 0; cabin < lift.size(); cabin++) {
17
            for (int peopleInCabin = lift.get(cabin); peopleInCabin < 4; peopleInCabin++) {
18
                people--;
19
                if (people < 0) {
20
                    noMorePeople = true;
21
                    break;
22
                }
23
                lift.set(cabin, peopleInCabin + 1);
24
            }
25
            if (noMorePeople) {
26
                break;
27
            }
28
        }
29
        if (noMorePeople) {
30
            System.out.println("The lift has empty spots!");
31
            System.out.print(lift.toString().replaceAll("[\\[\\],]", ""));
32
        }
33
        if (!noMorePeople && people > 0) {
34
            System.out.printf("There isn't enough space! %d people in a queue!\n", people);
35
            System.out.print(lift.toString().replaceAll("[\\[\\],]", ""));
36
        }
37
        if (!noMorePeople && people == 0) {
38
            System.out.print(lift.toString().replaceAll("[\\[\\],]", ""));
39
        }
40
    }
41
}