Roadstar3

Archery

Feb 27th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.07 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.  
  73.                     } else if (command[0].equals("Right")) {
  74.  
  75.                         int shot = (start + lenght) % target.length;
  76.                         if (target[shot] < 5) {
  77.                             score = score + target[shot];
  78.                             target[shot] = 0;
  79.                         } else {
  80.                             score = score + 5;
  81.                             target[shot] = target[shot] - 5;
  82.                         }
  83.  
  84.                     }
  85.  
  86.                     break;
  87.             }
  88.  
  89.  
  90.             action = scanner.nextLine();
  91.         }
  92.  
  93.         String[] output = new String[target.length];
  94.  
  95.         for (int i = 0; i < target.length; i++) {
  96.             output[i] = String.valueOf(target[i]);
  97.         }
  98.  
  99.         System.out.println(String.join(" - ", output));
  100.         System.out.printf("Iskren finished the archery tournament with %d points!%n", score);
  101.     }
  102. }
Add Comment
Please, Sign In to add comment