Advertisement
CR7CR7

CupidonAngel

Jun 15th, 2023
670
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.94 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.        
  10.         String[] input = scanner.nextLine().split("@");
  11.         ArrayList<Integer> neighborhood = new ArrayList<>();
  12.         for (String s : input) {
  13.             neighborhood.add(Integer.parseInt(s));
  14.         }
  15.  
  16.      
  17.         int position = 0;
  18.         int houses = neighborhood.size();
  19.  
  20.        
  21.         String command = scanner.nextLine();
  22.         while (!command.equals("Love!")) {
  23.          
  24.             int jump = Integer.parseInt(command.split(" ")[1]);
  25.  
  26.          
  27.             position += jump;
  28.  
  29.            
  30.             if (position >= neighborhood.size()) {
  31.                 position = 0;
  32.             }
  33.  
  34.            
  35.             houses = checkHouses(neighborhood, position);
  36.  
  37.            
  38.             command = scanner.nextLine();
  39.         }
  40.  
  41.        
  42.         System.out.println("Cupid's last position was " + position + ".");
  43.         if (houses == 0) {
  44.             System.out.println("Mission was successful.");
  45.         } else {
  46.             System.out.println("Cupid has failed " + houses + " places.");
  47.         }
  48.     }
  49.  
  50.    
  51.     public static int checkHouses(ArrayList<Integer> neighborhood, int position) {
  52.        
  53.         int hearts = neighborhood.get(position);
  54.  
  55.        
  56.         if (hearts > 0) {
  57.             hearts -= 2;
  58.             neighborhood.set(position, hearts);
  59.             if (hearts == 0) {
  60.                 System.out.println("Place " + position + " has Valentine's day.");
  61.             }
  62.         } else {
  63.            
  64.             System.out.println("Place " + position + " already had Valentine's day.");
  65.         }
  66.  
  67.        
  68.         int remaining = 0;
  69.  
  70.        
  71.         for (int h : neighborhood) {
  72.             if (h > 0) {
  73.                 remaining++;
  74.             }
  75.         }
  76.  
  77.         return remaining;
  78.     }
  79. }
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement