Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.util.stream.Collectors;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String input = scanner.nextLine();
- List<Integer> field = Arrays.stream(input.split("\\|"))
- .map(Integer::parseInt).collect(Collectors.toList());
- String command = scanner.nextLine();
- int finalScore = 0;
- while (!"Game over".equals(command)) {
- String[] tokens = command.split("[@\\s+]");
- switch (tokens[0]) {
- case "Shoot":
- if (tokens[1].equals("Left")) {
- int startIndex = Integer.parseInt(tokens[2]);
- int lenght = Integer.parseInt(tokens[3]);
- int finalIndex = startIndex;
- if (startIndex >= 0 && startIndex < field.size()) {
- for (int i = 0; i < lenght; i++) {
- finalIndex--;
- if (finalIndex < 0) {
- finalIndex = field.size() - 1;
- }
- }
- int currentTarget = field.get(finalIndex);
- if (currentTarget>5) {
- field.set(finalIndex, currentTarget - 5);
- finalScore += 5;
- } else {
- finalScore+=currentTarget;
- field.set(finalIndex,0);
- }
- }
- } else {
- int startIndex = Integer.parseInt(tokens[2]);
- int length = Integer.parseInt(tokens[3]);
- int finalIndex = startIndex;
- if (startIndex >= 0 && startIndex < field.size()) {
- for (int i = 0; i < length; i++) {
- finalIndex++;
- if (finalIndex >= field.size()) {
- finalIndex = 0;
- }
- }
- int currentTarget = field.get(finalIndex);
- if (currentTarget>5){
- field.set(finalIndex, currentTarget - 5);
- finalScore += 5;
- } else {
- finalScore+=currentTarget;
- field.set(finalIndex,0);
- }
- }
- }
- break;
- case "Reverse":
- Collections.reverse(field);
- break;
- }
- command = scanner.nextLine();
- }
- for (int i = 0; i < field.size() ; i++) {
- if (i!=field.size()-1){
- System.out.printf("%d - ",field.get(i));
- } else {
- System.out.printf("%d",field.get(i));
- }
- }
- System.out.println();
- System.out.println("Iskren finished the archery tournament with"+ " " + finalScore + " points!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement