Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package MidExam.O4;
- import java.util.Arrays;
- import java.util.List;
- import java.util.Scanner;
- import java.util.stream.Collectors;
- public class O3HeartDelivery {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- List<Integer> test = Arrays.stream(scanner.nextLine().split("@")).
- map(Integer::parseInt).collect(Collectors.toList());
- String command = scanner.nextLine();
- int cupidIndex = 0;
- while (!command.equals("Love!")) {
- int type = Integer.parseInt(command.split("\\s+")[1]);
- cupidIndex += type;
- if (cupidIndex >= test.size()) {
- cupidIndex = 0;
- }
- if (test.get(cupidIndex) <= 0) {
- System.out.printf("Place %d already had Valentine's day.%n", cupidIndex);
- } else {
- test.set(cupidIndex, test.get(cupidIndex) - 2);
- if (test.get(cupidIndex) <= 0) {
- System.out.printf("Place %d has Valentine's day.%n", cupidIndex);
- }
- }
- command = scanner.nextLine();
- }
- System.out.printf("Cupid's last position was %d.%n", cupidIndex);
- boolean isSuccessful = true;
- for (int house : test) {
- if (house != 0) {
- isSuccessful = false;
- break;
- }
- }
- int count = 0;
- for (int house : test) {
- if (house != 0) {
- count++;
- }
- }
- if (isSuccessful) {
- System.out.println("Mission was successful.");
- } else {
- System.out.printf("Cupid has failed %d places.", count);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment