Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. package PracticeMidExam;
  2.  
  3. import java.lang.reflect.Array;
  4. import java.sql.SQLOutput;
  5. import java.util.ArrayList;
  6. import java.util.Arrays;
  7. import java.util.Scanner;
  8.  
  9.  
  10. public class ArcheryTournament {
  11. public static void main(String[] arg) {
  12. Scanner sc = new Scanner(System.in);
  13.  
  14. int[] numbers = Arrays.stream(sc.nextLine().split("\\|"))
  15. .mapToInt(e -> Integer.parseInt(e)).toArray();
  16.  
  17. String input = sc.nextLine();
  18. int iskrenPoints = 0;
  19. int[] reverseNumbers = new int[numbers.length];
  20.  
  21. while(!"Game Over".equals(input)){
  22.  
  23. String[] commands = input.split("@");
  24. String command = commands[0];
  25. int starIndex = 0;
  26. int length = 0;
  27. if("Shoot Left".equals(command)) {
  28.  
  29. starIndex = Integer.parseInt(commands[1]);
  30. length = Integer.parseInt(commands[2]);
  31.  
  32. if(starIndex >=0 && starIndex < numbers.length){
  33.  
  34. while(length !=0){
  35.  
  36. if (starIndex > 0) {
  37.  
  38. starIndex--;
  39. length--;
  40.  
  41. }else if (starIndex == 0){
  42.  
  43. starIndex = numbers.length-1;
  44. length--;
  45.  
  46. }
  47. }
  48.  
  49. if(numbers[starIndex] >= 5){
  50.  
  51. numbers[starIndex] -= 5;
  52. iskrenPoints+=5;
  53.  
  54. }else{
  55.  
  56. iskrenPoints +=numbers[starIndex];
  57. numbers[starIndex] = 0;
  58.  
  59. }
  60.  
  61. }
  62. }
  63. else if ("Shoot Right".equals(command)){
  64.  
  65. starIndex = Integer.parseInt(commands[1]);
  66. length = Integer.parseInt(commands[2]);
  67.  
  68. if(starIndex >=0 && starIndex < numbers.length){
  69.  
  70. while (length !=0){
  71.  
  72. if(starIndex < numbers.length - 1){
  73.  
  74. starIndex++;
  75. length--;
  76.  
  77. }
  78. else if(starIndex == numbers.length-1){
  79.  
  80. starIndex = 0;
  81. length--;
  82. }
  83. }
  84.  
  85. if(numbers[starIndex] >=5){
  86.  
  87. numbers[starIndex] -= 5;
  88. iskrenPoints += 5;
  89.  
  90. }
  91. else{
  92.  
  93. iskrenPoints += numbers[starIndex];
  94. numbers[starIndex] = 0;
  95. }
  96. }
  97. }
  98. else if("Reverse".equals(command)){
  99.  
  100.  
  101.  
  102. for (int i = numbers.length-1; i >= 0 ; i--) {
  103.  
  104. reverseNumbers[numbers.length-1-i] = numbers[i];
  105.  
  106. }
  107. }
  108.  
  109.  
  110.  
  111. input = sc.nextLine();
  112. }
  113.  
  114.  
  115.  
  116. for (int number : reverseNumbers) {
  117. System.out.print(number + " " + "-");
  118. }
  119.  
  120. System.out.println();
  121.  
  122. System.out.printf("Iskren finished the archery tournament with %d points!", iskrenPoints);
  123. }
  124.  
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement