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