Yargi

ShootForTheWin

Jun 22nd, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.List;
  3. import java.util.Scanner;
  4. import java.util.stream.Collectors;
  5.  
  6. public class ShootForTheWin {
  7.     public static void main(String[] args) {
  8.         Scanner sc = new Scanner(System.in);
  9.         List<Integer> targets = Arrays.stream(sc.nextLine().split("\\s+")).map(Integer::parseInt).collect(Collectors.toList());
  10.         int count = 0;
  11.  
  12.         String n;
  13.         while (!"End".equals(n = sc.nextLine())){
  14.             int shot = Integer.parseInt(n);
  15.             if (shot < targets.size() && shot >= 0) {
  16.                 int actualTarget = targets.get(shot);
  17.                 if (actualTarget != -1) {
  18.                     targets.set(shot, -1);
  19.                     count++;
  20.                 }
  21.                 for (int i = 0; i < targets.size(); i++) {
  22.                     if (targets.get(i) != -1) {
  23.                         if (targets.get(i) <= actualTarget) {
  24.                             targets.set(i, targets.get(i) + actualTarget);
  25.                         } else {
  26.                             targets.set(i, targets.get(i) - actualTarget);
  27.                         }
  28.                     }
  29.                 }
  30.             }
  31.         }
  32.         System.out.printf("Shot targets: %d -> %s", count, targets.toString().replaceAll("[\\[\\],]", ""));
  33.     }
  34. }
Add Comment
Please, Sign In to add comment