Untitled
unknown
plain_text
2 years ago
3.0 kB
5
Indexable
import java.util.Scanner; public class Test_02 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String text = sc.nextLine(); String[] textParts = text.split("\\|"); int n = textParts.length; int[] targets = new int[n]; for (int i = 0; i < n; i++) { targets[i] = Integer.parseInt(textParts[i]); } int playersPoints = 0; while (true){ String command = sc.nextLine(); if (command.equals("Game over")) { break; } if (command.equals("Reverse")){ int[] reversedArray = new int[n]; for (int i = 0; i < n ; i++) { reversedArray[i] = targets[n-1-i]; } System.arraycopy(reversedArray, 0, targets, 0, reversedArray.length); continue; } String[] commandParts = command.split("@"); String shoots = commandParts[0]; int index = Integer.parseInt(commandParts[1]); int length = Integer.parseInt(commandParts[2]); if (length > n){ if (length % n == 0){ length = n; }else { length = length % n; } } if (shoots.equals("Shoot Left")){ if (index < 0 || index >= n) continue; int targetIndex = index - length; if (targetIndex < 0) targetIndex = n - Math.abs(targetIndex); if (targets[targetIndex] < 5){ int newPlayersPoints = targets[targetIndex]; targets[targetIndex] = 0; playersPoints = playersPoints + newPlayersPoints; }else { targets[targetIndex] = targets[targetIndex] - 5; playersPoints = playersPoints + 5; } } else if (shoots.equals("Shoot Right")){ if (index < 0 || index >= n) continue; int targetIndex = index + length; if (targetIndex > n) targetIndex = targetIndex - n; if (targets[targetIndex] < 5){ int newPlayersPoints = targets[targetIndex]; targets[targetIndex] = 0; playersPoints = playersPoints + newPlayersPoints; }else { targets[targetIndex] = targets[targetIndex] - 5; playersPoints = playersPoints + 5; } } } for (int i = 0; i < n-1; i++) { System.out.printf("%d - ", targets[i]); } System.out.printf("%d\n", targets[n-1]); System.out.printf("John finished the archery tournament with %d points!", playersPoints); } }
Editor is loading...