Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package MidExam;
- import java.util.*;
- import java.util.stream.Collectors;
- public class HeartDelivery {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] input = scanner.nextLine().split("@");
- List<Integer> neighborhood = Arrays.stream(input).map(Integer::parseInt).collect(Collectors.toList());
- String command = scanner.nextLine();
- int indexNow = 0;
- while (!"Love!".equals(command)) {
- String[] tokens = command.split("\\s+");
- int jumpLength = Integer.parseInt(tokens[1]);
- indexNow += jumpLength;
- if (indexNow >= neighborhood.size()) {
- indexNow = 0;
- }
- if (equalZero(neighborhood.get(indexNow))) {
- System.out.println(String.format("Place %d already had Valentine's day.", indexNow));
- command = scanner.nextLine();
- continue;
- }
- neighborhood.set(indexNow, neighborhood.get(indexNow) - 2);
- if (equalZero(neighborhood.get(indexNow))) {
- System.out.println(String.format("Place %d has Valentine's day.", indexNow));
- }
- command = scanner.nextLine();
- }
- System.out.println(String.format("Cupid's last position was %s.", indexNow));
- int count = 0;
- for (Integer integer : neighborhood) {
- if (!(integer == 0)) {
- count++;
- }
- }
- if (count != 0) {
- System.out.println(String.format("Cupid has failed %d places.", count));
- } else {
- System.out.println("Mission was successful.");
- }
- }
- private static boolean equalZero(int indexNow) {
- return indexNow == 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment