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