RGAlex

O3. Heart Delivery / O4. Mid Exam Retake

Feb 23rd, 2021
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.74 KB | None | 0 0
  1. package MidExam.O4;
  2.  
  3. import java.util.Arrays;
  4. import java.util.List;
  5. import java.util.Scanner;
  6. import java.util.stream.Collectors;
  7.  
  8. public class O3HeartDelivery {
  9.     public static void main(String[] args) {
  10.         Scanner scanner = new Scanner(System.in);
  11.         List<Integer> test = Arrays.stream(scanner.nextLine().split("@")).
  12.                 map(Integer::parseInt).collect(Collectors.toList());
  13.  
  14.         String command = scanner.nextLine();
  15.         int cupidIndex = 0;
  16.         while (!command.equals("Love!")) {
  17.             int type = Integer.parseInt(command.split("\\s+")[1]);
  18.             cupidIndex += type;
  19.             if (cupidIndex >= test.size()) {
  20.                 cupidIndex = 0;
  21.             }
  22.             if (test.get(cupidIndex) <= 0) {
  23.                 System.out.printf("Place %d already had Valentine's day.%n", cupidIndex);
  24.             } else {
  25.                 test.set(cupidIndex, test.get(cupidIndex) - 2);
  26.                 if (test.get(cupidIndex) <= 0) {
  27.                     System.out.printf("Place %d has Valentine's day.%n", cupidIndex);
  28.                 }
  29.             }
  30.             command = scanner.nextLine();
  31.         }
  32.         System.out.printf("Cupid's last position was %d.%n", cupidIndex);
  33.         boolean isSuccessful = true;
  34.         for (int house : test) {
  35.             if (house != 0) {
  36.                 isSuccessful = false;
  37.                 break;
  38.             }
  39.         }
  40.         int count = 0;
  41.         for (int house : test) {
  42.             if (house != 0) {
  43.                 count++;
  44.             }
  45.         }
  46.         if (isSuccessful) {
  47.             System.out.println("Mission was successful.");
  48.         } else {
  49.             System.out.printf("Cupid has failed %d places.", count);
  50.         }
  51.     }
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment