Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. import java.sql.Array;
  2. import java.util.Arrays;
  3. import java.util.Scanner;
  4.  
  5. public class classes {
  6.  
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9.  
  10. int[] target = Arrays.stream(scanner.nextLine().split("\\|"))
  11. .mapToInt(e -> Integer.parseInt(e)).toArray();
  12.  
  13. int score = 0;
  14.  
  15. String action = scanner.nextLine();
  16.  
  17. while (!"Game over".equals(action)) {
  18.  
  19. String[] tokens = action.split("\\s");
  20.  
  21. switch (tokens[0]) {
  22. case "Reverse":
  23. int[] reversedTarget = new int[target.length];
  24. int index = 0;
  25.  
  26. for (int i = target.length - 1; i >= 0; i--) {
  27.  
  28. reversedTarget[index] = target[i];
  29. index++;
  30. }
  31. target = reversedTarget;
  32.  
  33. break;
  34.  
  35. case "Shoot":
  36.  
  37. String[] command = tokens[1].split("@");
  38. int start = Integer.parseInt(command[1]);
  39.  
  40. if (start < 0 || start >= target.length) {
  41. action = scanner.nextLine();
  42. continue;
  43. }
  44.  
  45. int lenght = Integer.parseInt(command[2]);
  46.  
  47. if (command[0].equals("Left")) {
  48.  
  49. int i = start;
  50. int l = lenght;
  51.  
  52. while (l != 0) {
  53.  
  54. if (i == 0) {
  55. i = target.length -1;
  56. l--;
  57. } else {
  58. i--;
  59. l--;
  60. }
  61. }
  62.  
  63. int shot = i;
  64.  
  65. if (target[shot] < 5) {
  66. score = score + target[shot];
  67. target[shot] = 0;
  68. } else {
  69. score = score + 5;
  70. target[shot] = target[shot] - 5;
  71. }
  72. } else if (command[0].equals("Right")) {
  73.  
  74. int shot = (start + lenght) % target.length;
  75. if (target[shot] < 5) {
  76. score = score + target[shot];
  77. target[shot] = 0;
  78. } else {
  79. score = score + 5;
  80. target[shot] = target[shot] - 5;
  81. }
  82.  
  83. }
  84. break;
  85. }
  86. action = scanner.nextLine();
  87. }
  88.  
  89. String[] output = new String[target.length];
  90.  
  91. for (int i = 0; i < target.length; i++) {
  92. output[i] = String.valueOf(target[i]);
  93. }
  94.  
  95. System.out.println(String.join(" - ", output));
  96. System.out.printf("Iskren finished the archery tournament with %d points!%n", score);
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement