Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- import java.util.Scanner;
- public class ex1210_02_ArcheryTournament {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] targetsSplit = scanner.nextLine().split("\\|");
- List<Integer> targets = new ArrayList<>();
- for (String currentTarget : targetsSplit) {
- targets.add(Integer.parseInt(currentTarget));
- }
- String command = scanner.nextLine();
- int pointsWon = 0;
- while (!command.contains("Game over")) {
- String[] arrayCommands = command.split("\\@");
- String action = arrayCommands[0];
- switch (action) {
- case "Shoot Left":
- int startIndex = Integer.parseInt(arrayCommands[1]);
- int length = Integer.parseInt(arrayCommands[2]);
- if (startIndex < 0 || startIndex > targets.size() - 1) {
- break;
- } else if (startIndex >= 0 || startIndex < targets.size() - 1) {
- int targetToShoot = startIndex - length;
- if (length > targets.size() - 1) {
- startIndex = length % targets.size();
- targetToShoot = targets.size() - startIndex;
- } else if (targetToShoot < 0) {
- targetToShoot = targets.size() - Math.abs(targetToShoot);
- }
- pointsWon = getPointsWon(targets, pointsWon, targetToShoot);
- } else {
- break;
- }
- break;
- case "Shoot Right":
- startIndex = Integer.parseInt(arrayCommands[1]);
- length = Integer.parseInt(arrayCommands[2]);
- if (startIndex < 0 || startIndex > targets.size() - 1) {
- break;
- } else if (startIndex >= 0 || startIndex < targets.size() - 1) {
- int targetToShoot = startIndex + length;
- if (length > targets.size() - 1) {
- int indexExceed = length % targets.size();
- targetToShoot = startIndex + indexExceed;
- if(targetToShoot > targets.size() - 1){
- targetToShoot = indexExceed-1;
- }
- }
- pointsWon = getPointsWon(targets, pointsWon, targetToShoot);
- }
- break;
- case "Reverse":
- Collections.reverse(targets);
- break;
- }
- command = scanner.nextLine();
- }
- for (int i = 0; i < targets.size(); i++) {
- if (i == targets.size() - 1) {
- System.out.print(targets.get(i));
- } else {
- System.out.print(targets.get(i) + " - ");
- }
- }
- System.out.println();
- System.out.printf("Iskren finished the archery tournament with %d points!", pointsWon);
- }
- public static int getPointsWon(List<Integer> targets, int pointsWon, int targetToShoot) {
- int currentTargetAmount = targets.get(targetToShoot);
- if (currentTargetAmount >= 5) {
- targets.set(targetToShoot, currentTargetAmount - 5);
- pointsWon = pointsWon + 5;
- } else if (currentTargetAmount < 5) {
- targets.set(targetToShoot, 0);
- pointsWon = pointsWon + currentTargetAmount;
- }
- return pointsWon;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement