Advertisement
markopizzy

Untitled

Feb 29th, 2020
625
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.List;
  3. import java.util.Scanner;
  4.  
  5. public class JF_Mid_Exam_29_02_2020_Heart_Delivery {
  6. public static void main(String[] args) {
  7. Scanner scanner = new Scanner(System.in);
  8.  
  9. List<Integer> neighborhood = readIntegerList(scanner);
  10. String input = scanner.nextLine();
  11. int celebrityCount = 0;
  12. int lastPosition = 0;
  13.  
  14. while (!"Love!".equals(input)) {
  15. String[] tokens = input.split(" ");
  16. int jump = Integer.parseInt(tokens[1]);
  17.  
  18. if (jump >= neighborhood.size()) {
  19. int result = neighborhood.get(0) - 2;
  20. if (result < 0) {
  21. System.out.println(String.format("Place %d already had Valentine's day.", neighborhood.get(0)));
  22. } else {
  23. neighborhood.set(0, result);
  24. if (result == 0) {
  25. celebrityCount++;
  26. System.out.println(String.format("Place %d has Valentine's day.", neighborhood.get(0)));
  27. }
  28. }
  29. } else {
  30. int result = neighborhood.get(jump) - 2;
  31. if (result < 0) {
  32. System.out.println(String.format("Place %d already had Valentine's day.", neighborhood.get(jump)));
  33.  
  34. } else {
  35. neighborhood.set(jump, result);
  36. if (result == 0) {
  37. celebrityCount++;
  38. System.out.println(String.format("Place %d has Valentine's day.", jump));
  39. }
  40. }
  41. lastPosition = jump;
  42. }
  43. input = scanner.nextLine();
  44. }
  45. System.out.println(String.format("Cupid's last position was %d.", lastPosition));
  46. if (celebrityCount < neighborhood.size()) {
  47. System.out.println(String.format("Cupid has failed %d places.", neighborhood.size() - celebrityCount));
  48. }
  49. }
  50. private static List<Integer> readIntegerList(Scanner scanner) {
  51. String[] input = scanner.nextLine().split("@");
  52. List<Integer> output = new ArrayList<>();
  53. for (String element : input) {
  54. output.add(Integer.parseInt(element));
  55. }
  56. return output;
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement