Advertisement
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 Pr3PresentDelivery_v2 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- List<Integer> peopleInHouse = Arrays.stream(scanner.nextLine().split("@"))
- .map(Integer::parseInt)
- .collect(Collectors.toList());
- int santaIndex = 0;
- String command = scanner.nextLine();
- while (!(command.equals("Merry Xmas!"))) {
- String[] arrCommand = command.split(" ");
- if (arrCommand[0].equals("Jump")) {
- int timesToJump = Integer.parseInt(arrCommand[1]);
- if (santaIndex + timesToJump >= peopleInHouse.size()) {
- santaIndex = (santaIndex + timesToJump) % peopleInHouse.size();
- } else {
- santaIndex += timesToJump;
- }
- if (peopleInHouse.get(santaIndex) == 0) {
- System.out.println("House " + santaIndex + " will have a Merry Christmas.");
- } else {
- peopleInHouse.set(santaIndex, peopleInHouse.get(santaIndex) - 2);
- }
- }
- command = scanner.nextLine();
- }
- int coutFailedHouses = 0;
- boolean isHavePresents = true;
- for (Integer integer : peopleInHouse) {
- if (integer != 0) {
- isHavePresents = false;
- coutFailedHouses++;
- }
- }
- if (isHavePresents) {
- System.out.println("Santa's last position was " + santaIndex + ".");
- System.out.println("Mission was successful.");
- } else {
- System.out.println("Santa's last position was " + santaIndex + ".");
- System.out.println("Santa has failed " + coutFailedHouses + " houses.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement