Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.List;
- import java.util.Scanner;
- import java.util.stream.Collectors;
- public class TheLift_02 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int people = Integer.parseInt(scanner.nextLine());
- boolean noMorePeople = false;
- List<Integer> lift = Arrays.stream(scanner.nextLine().split("\\s+")).
- map(Integer::parseInt).collect(Collectors.toList());
- for (int cabin = 0; cabin < lift.size(); cabin++) {
- for (int peopleInCabin = lift.get(cabin); peopleInCabin < 4; peopleInCabin++) {
- people--;
- if (people < 0) {
- noMorePeople = true;
- break;
- }
- lift.set(cabin, peopleInCabin + 1);
- }
- if (noMorePeople) {
- break;
- }
- }
- if (noMorePeople) {
- System.out.println("The lift has empty spots!");
- System.out.print(lift.toString().replaceAll("[\\[\\],]", ""));
- }
- if (!noMorePeople && people > 0) {
- System.out.printf("There isn't enough space! %d people in a queue!\n", people);
- System.out.print(lift.toString().replaceAll("[\\[\\],]", ""));
- }
- if (!noMorePeople && people == 0) {
- System.out.print(lift.toString().replaceAll("[\\[\\],]", ""));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment