Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.sql.Array;
- import java.util.Arrays;
- import java.util.Scanner;
- public class classes {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int[] target = Arrays.stream(scanner.nextLine().split("\\|"))
- .mapToInt(e -> Integer.parseInt(e)).toArray();
- int score = 0;
- String action = scanner.nextLine();
- while (!"Game over".equals(action)) {
- String[] tokens = action.split("\\s");
- switch (tokens[0]) {
- case "Reverse":
- int[] reversedTarget = new int[target.length];
- int index = 0;
- for (int i = target.length - 1; i >= 0; i--) {
- reversedTarget[index] = target[i];
- index++;
- }
- target = reversedTarget;
- break;
- case "Shoot":
- String[] command = tokens[1].split("@");
- int start = Integer.parseInt(command[1]);
- if (start < 0 || start >= target.length) {
- action = scanner.nextLine();
- continue;
- }
- int lenght = Integer.parseInt(command[2]);
- if (command[0].equals("Left")) {
- int i = start;
- int l = lenght;
- while (l != 0) {
- if (i == 0) {
- i = target.length -1;
- l--;
- } else {
- i--;
- l--;
- }
- }
- int shot = i;
- if (target[shot] < 5) {
- score = score + target[shot];
- target[shot] = 0;
- } else {
- score = score + 5;
- target[shot] = target[shot] - 5;
- }
- } else if (command[0].equals("Right")) {
- int shot = (start + lenght) % target.length;
- if (target[shot] < 5) {
- score = score + target[shot];
- target[shot] = 0;
- } else {
- score = score + 5;
- target[shot] = target[shot] - 5;
- }
- }
- break;
- }
- action = scanner.nextLine();
- }
- String[] output = new String[target.length];
- for (int i = 0; i < target.length; i++) {
- output[i] = String.valueOf(target[i]);
- }
- System.out.println(String.join(" - ", output));
- System.out.printf("Iskren finished the archery tournament with %d points!%n", score);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement