Advertisement
mitko30009

fd

Jun 25th, 2020
1,835
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Demo {
  4.  
  5.     public static void main(String[] args) {
  6.         Scanner scan = new Scanner(System.in);
  7.  
  8.         int[] targets = Arrays.stream(scan.nextLine().split("\\s+")).mapToInt(Integer::parseInt).toArray();
  9.  
  10.         int successfullShots = 0;
  11.  
  12.         String input = scan.nextLine();
  13.  
  14.         while (!input.equals("End")) {
  15.             int index = Integer.parseInt(input);
  16.  
  17.             if (index < targets.length) {
  18.                 int num = targets[index];
  19.                 targets[index] = -1;
  20.                 successfullShots++;
  21.                 for (int i = 0; i < targets.length; i++) {
  22.                     if (i != index) {
  23.                         if (targets[i] > num) {
  24.                             targets[i] -= num;
  25.                         } else if (targets[i] != -1) {
  26.                             targets[i] += num;
  27.                         }
  28.                     }
  29.                 }
  30.             }
  31.  
  32.             input = scan.nextLine();
  33.         }
  34.  
  35.         System.out.print(String.format("Shot targets: %d -> ", successfullShots));
  36.  
  37.         for (int target : targets) {
  38.             System.out.print(target + " ");
  39.         }
  40.  
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement