View difference between Paste ID: 3XC6Nt7Z and EmWH0u35
SHOW: | | - or go back to the newest paste.
1
package com.softuni;
2
3
import java.util.Arrays;
4
import java.util.List;
5
import java.util.Scanner;
6
import java.util.stream.Collectors;
7
8
public class TheLift {
9
    public static void main(String[] args) {
10
        Scanner scanner = new Scanner(System.in);
11
        int peopleInQueue = Integer.parseInt(scanner.nextLine());
12
        String[] userInput = scanner.nextLine().split(" ");
13
14
        int[] liftCabins = Arrays.stream(userInput).mapToInt(Integer::parseInt).toArray();
15
//        List<Integer> liftCabinsList = Arrays.stream(userInput).map(Integer::parseInt).collect(Collectors.toList());
16
17
        for (int i = 0; i < liftCabins.length; i++) {
18
           //Влизат хора от опашката
19
           int peopleInCabin = liftCabins[i];
20
           int freeSpace = 4 - peopleInCabin;
21
22
           if(peopleInCabin == 4){
23
               continue;
24
           }
25
26
           if(freeSpace >= peopleInQueue){
27
                liftCabins[i] = liftCabins[i] + peopleInQueue;
28
                peopleInQueue = 0;
29
                //tUK
30
                break;
31
           }
32
33
           liftCabins[i] = 4;
34
           peopleInQueue = peopleInQueue - freeSpace;
35
        }
36
37
        boolean hasEmptySeats = false;
38
        for (int peopleInCabin : liftCabins) {
39
            if(peopleInCabin < 4){
40
                hasEmptySeats = true;
41
                break;
42
            }
43
        }
44
45
46
        if(hasEmptySeats){
47
            System.out.println("The lift has empty spots!");
48
        } else if (!hasEmptySeats && peopleInQueue!=0){
49
            System.out.printf("There isn't enough space! %d people in a queue!%n", peopleInQueue);
50
        }
51
        // нямаме свободни места, но и хората в опашката са свършили
52
        Arrays.stream(liftCabins).forEach(e -> System.out.print(e + " "));
53
    }
54
}
55