Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Scanner;
- public class Cupid {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] input = scanner.nextLine().split("@");
- int[] neighborhood = Arrays.stream(input).mapToInt(Integer::parseInt).toArray();
- int index = 0;
- String command = scanner.nextLine();
- while (!command.equals("Love!")) {
- int length = Integer.parseInt(command.split(" ")[1]);
- index += length;
- if (index >= neighborhood.length) {
- index = 0;
- }
- neighborhood[index] -= 2;
- if (neighborhood[index] == 0) {
- System.out.println("Place " + index + " has Valentine's day.");
- } else if (neighborhood[index] < 0) {
- System.out.println("Place " + index + " already had Valentine's day.");
- }
- command = scanner.nextLine();
- }
- // Print Cupid's final position
- System.out.println("Cupid's last position was " + index + ".");
- int successful = 0;
- int failed = 0;
- for (int house : neighborhood) {
- if (house <= 0) {
- successful++;
- } else {
- failed++;
- }
- }
- if (failed == 0) {
- System.out.println("Mission was successful.");
- } else {
- System.out.println("Cupid has failed " + failed + " places.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement