Advertisement
Guest User

Untitled

a guest
Mar 8th, 2019
440
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.26 KB | None | 0 0
  1. import java.lang.reflect.Array;
  2. import java.text.DecimalFormat;
  3. import java.util.*;
  4. import java.util.stream.Collectors;
  5.  
  6. public class kur {
  7.  
  8.     public static void main(String[] args) {
  9.         Scanner scanner = new Scanner(System.in);
  10.  
  11.         int[] houses = Arrays.stream(scanner.nextLine().split("@")).mapToInt(Integer::parseInt).filter(e -> e % 2 == 0).toArray();
  12.         String input;
  13.         int currentPosition = 0;
  14.  
  15.         while (!"Merry Xmas!".equals(input = scanner.nextLine())) {
  16.  
  17.             String[] command = input.split(" ");
  18.             currentPosition =  (currentPosition + Integer.parseInt(command[1])) % houses.length;
  19.  
  20.             if (houses[currentPosition] != 0) {
  21.                 houses[currentPosition] -= 2;
  22.             }else {
  23.                 System.out.printf("House %d will have a Merry Christmas.\n", currentPosition);
  24.             }
  25.         }
  26.         if (Arrays.stream(houses).sum() == 0) {
  27.             System.out.printf("Santa's last position was %d.\nMission was successful.", currentPosition);
  28.         }else {
  29.             houses = Arrays.stream(houses).filter(e -> e > 0).toArray();
  30.             System.out.printf("Santa's last position was %d.\nSanta has failed %d houses.", currentPosition, houses.length);
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement