Advertisement
IvaAnd

Retake_10DEC_Archery Tournament_02

Jul 3rd, 2020
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Collections;
  3. import java.util.List;
  4. import java.util.Scanner;
  5.  
  6. public class ex1210_02_ArcheryTournament {
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9.  
  10. String[] targetsSplit = scanner.nextLine().split("\\|");
  11.  
  12. List<Integer> targets = new ArrayList<>();
  13.  
  14. for (String currentTarget : targetsSplit) {
  15. targets.add(Integer.parseInt(currentTarget));
  16. }
  17. String command = scanner.nextLine();
  18. int pointsWon = 0;
  19. while (!command.contains("Game over")) {
  20. String[] arrayCommands = command.split("\\@");
  21.  
  22. String action = arrayCommands[0];
  23. switch (action) {
  24. case "Shoot Left":
  25. int startIndex = Integer.parseInt(arrayCommands[1]);
  26. int length = Integer.parseInt(arrayCommands[2]);
  27. if (startIndex < 0 || startIndex > targets.size() - 1) {
  28. break;
  29. } else if (startIndex >= 0 || startIndex < targets.size() - 1) {
  30. int targetToShoot = startIndex - length;
  31. if (length > targets.size() - 1) {
  32. startIndex = length % targets.size();
  33. targetToShoot = targets.size() - startIndex;
  34. } else if (targetToShoot < 0) {
  35. targetToShoot = targets.size() - Math.abs(targetToShoot);
  36. }
  37. pointsWon = getPointsWon(targets, pointsWon, targetToShoot);
  38. } else {
  39. break;
  40. }
  41. break;
  42. case "Shoot Right":
  43. startIndex = Integer.parseInt(arrayCommands[1]);
  44. length = Integer.parseInt(arrayCommands[2]);
  45. if (startIndex < 0 || startIndex > targets.size() - 1) {
  46. break;
  47. } else if (startIndex >= 0 || startIndex < targets.size() - 1) {
  48. int targetToShoot = startIndex + length;
  49. if (length > targets.size() - 1) {
  50. int indexExceed = length % targets.size();
  51. targetToShoot = startIndex + indexExceed;
  52. if(targetToShoot > targets.size() - 1){
  53. targetToShoot = indexExceed-1;
  54. }
  55. }
  56. pointsWon = getPointsWon(targets, pointsWon, targetToShoot);
  57. }
  58. break;
  59. case "Reverse":
  60. Collections.reverse(targets);
  61. break;
  62. }
  63.  
  64. command = scanner.nextLine();
  65. }
  66. for (int i = 0; i < targets.size(); i++) {
  67. if (i == targets.size() - 1) {
  68. System.out.print(targets.get(i));
  69. } else {
  70. System.out.print(targets.get(i) + " - ");
  71. }
  72. }
  73. System.out.println();
  74. System.out.printf("Iskren finished the archery tournament with %d points!", pointsWon);
  75. }
  76.  
  77. public static int getPointsWon(List<Integer> targets, int pointsWon, int targetToShoot) {
  78. int currentTargetAmount = targets.get(targetToShoot);
  79. if (currentTargetAmount >= 5) {
  80. targets.set(targetToShoot, currentTargetAmount - 5);
  81. pointsWon = pointsWon + 5;
  82. } else if (currentTargetAmount < 5) {
  83. targets.set(targetToShoot, 0);
  84. pointsWon = pointsWon + currentTargetAmount;
  85. }
  86. return pointsWon;
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement