Advertisement
mirozspace

S_List_E

Apr 3rd, 2019
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.94 KB | None | 0 0
  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 Pr3PresentDelivery_v2 {
  7.     public static void main(String[] args) {
  8.         Scanner scanner = new Scanner(System.in);
  9.         List<Integer> peopleInHouse = Arrays.stream(scanner.nextLine().split("@"))
  10.                 .map(Integer::parseInt)
  11.                 .collect(Collectors.toList());
  12.  
  13.         int santaIndex = 0;
  14.         String command = scanner.nextLine();
  15.         while (!(command.equals("Merry Xmas!"))) {
  16.             String[] arrCommand = command.split(" ");
  17.  
  18.             if (arrCommand[0].equals("Jump")) {
  19.                 int timesToJump = Integer.parseInt(arrCommand[1]);
  20.                 if (santaIndex + timesToJump >= peopleInHouse.size()) {
  21.                     santaIndex = (santaIndex + timesToJump) % peopleInHouse.size();
  22.                 } else {
  23.                     santaIndex += timesToJump;
  24.                 }
  25.  
  26.                 if (peopleInHouse.get(santaIndex) == 0) {
  27.                     System.out.println("House " + santaIndex + " will have a Merry Christmas.");
  28.                 } else {
  29.                     peopleInHouse.set(santaIndex, peopleInHouse.get(santaIndex) - 2);
  30.                 }
  31.             }
  32.             command = scanner.nextLine();
  33.         }
  34.  
  35.  
  36.         int coutFailedHouses = 0;
  37.         boolean isHavePresents = true;
  38.         for (Integer integer : peopleInHouse) {
  39.             if (integer != 0) {
  40.                 isHavePresents = false;
  41.                 coutFailedHouses++;
  42.  
  43.  
  44.             }
  45.         }
  46.  
  47.         if (isHavePresents) {
  48.             System.out.println("Santa's last position was " + santaIndex + ".");
  49.             System.out.println("Mission was successful.");
  50.         } else {
  51.             System.out.println("Santa's last position was " + santaIndex + ".");
  52.             System.out.println("Santa has failed " + coutFailedHouses + " houses.");
  53.  
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement