Advertisement
Guest User

Untitled

a guest
Feb 29th, 2020
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.31 KB | None | 0 0
  1. import java.util.*;
  2. import java.util.stream.Collectors;
  3.  
  4. public class Main {
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         String input = scanner.nextLine();
  9.         List<Integer> field = Arrays.stream(input.split("\\|"))
  10.                 .map(Integer::parseInt).collect(Collectors.toList());
  11.         String command = scanner.nextLine();
  12.         int finalScore = 0;
  13.         while (!"Game over".equals(command)) {
  14.             String[] tokens = command.split("[@\\s+]");
  15.             switch (tokens[0]) {
  16.                 case "Shoot":
  17.                     if (tokens[1].equals("Left")) {
  18.                         int startIndex = Integer.parseInt(tokens[2]);
  19.                         int lenght = Integer.parseInt(tokens[3]);
  20.                         int finalIndex = startIndex;
  21.                         if (startIndex >= 0 && startIndex < field.size()) {
  22.                             for (int i = 0; i < lenght; i++) {
  23.                                 finalIndex--;
  24.                                 if (finalIndex < 0) {
  25.                                     finalIndex = field.size() - 1;
  26.                                 }
  27.                             }
  28.                                 int currentTarget = field.get(finalIndex);
  29.                             if (currentTarget>5) {
  30.                                 field.set(finalIndex, currentTarget - 5);
  31.                                 finalScore += 5;
  32.                             } else {
  33.                                 finalScore+=currentTarget;
  34.                                 field.set(finalIndex,0);
  35.                             }
  36.                         }
  37.  
  38.                     } else {
  39.                         int startIndex = Integer.parseInt(tokens[2]);
  40.                         int length = Integer.parseInt(tokens[3]);
  41.                         int finalIndex = startIndex;
  42.                         if (startIndex >= 0 && startIndex < field.size()) {
  43.                             for (int i = 0; i < length; i++) {
  44.                                 finalIndex++;
  45.                                 if (finalIndex >= field.size()) {
  46.                                     finalIndex = 0;
  47.                                 }
  48.                             }
  49.                                 int currentTarget = field.get(finalIndex);
  50.                             if (currentTarget>5){
  51.                                 field.set(finalIndex, currentTarget - 5);
  52.                                 finalScore += 5;
  53.                             } else {
  54.                                 finalScore+=currentTarget;
  55.                                 field.set(finalIndex,0);
  56.                             }
  57.                         }
  58.                     }
  59.                     break;
  60.                 case "Reverse":
  61.                     Collections.reverse(field);
  62.                     break;
  63.  
  64.             }
  65.  
  66.             command = scanner.nextLine();
  67.         }
  68.  
  69.         for (int i = 0; i < field.size() ; i++) {
  70.             if (i!=field.size()-1){
  71.                 System.out.printf("%d - ",field.get(i));
  72.             } else {
  73.                 System.out.printf("%d",field.get(i));
  74.             }
  75.         }
  76.         System.out.println();
  77.         System.out.println("Iskren finished the archery tournament with"+ " " + finalScore + " points!");
  78.  
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement