Advertisement
CR7CR7

HeatsOfCupidon

Jun 15th, 2023
724
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.65 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4. public class Cupid {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.        
  9.         String[] input = scanner.nextLine().split("@");
  10.        
  11.         int[] neighborhood = Arrays.stream(input).mapToInt(Integer::parseInt).toArray();
  12.        
  13.         int index = 0;
  14.        
  15.         String command = scanner.nextLine();
  16.         while (!command.equals("Love!")) {
  17.            
  18.             int length = Integer.parseInt(command.split(" ")[1]);
  19.            
  20.             index += length;
  21.            
  22.             if (index >= neighborhood.length) {
  23.                 index = 0;
  24.             }
  25.          
  26.             neighborhood[index] -= 2;
  27.            
  28.             if (neighborhood[index] == 0) {
  29.                 System.out.println("Place " + index + " has Valentine's day.");
  30.             } else if (neighborhood[index] < 0) {
  31.                 System.out.println("Place " + index + " already had Valentine's day.");
  32.             }
  33.            
  34.             command = scanner.nextLine();
  35.         }
  36.         // Print Cupid's final position
  37.         System.out.println("Cupid's last position was " + index + ".");
  38.      
  39.         int successful = 0;
  40.         int failed = 0;
  41.         for (int house : neighborhood) {
  42.             if (house <= 0) {
  43.                 successful++;
  44.             } else {
  45.                 failed++;
  46.             }
  47.         }
  48.        
  49.         if (failed == 0) {
  50.             System.out.println("Mission was successful.");
  51.         } else {
  52.             System.out.println("Cupid has failed " + failed + " places.");
  53.         }
  54.     }
  55. }
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement