RGAlex

O2. Shoot For The Win / O3. Mid Exam Retake

Feb 23rd, 2021
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.31 KB | None | 0 0
  1. package MidExam.O3;
  2.  
  3. import java.util.Arrays;
  4. import java.util.List;
  5. import java.util.Scanner;
  6. import java.util.stream.Collectors;
  7.  
  8. public class O2ShootForTheWin {
  9.     public static void main(String[] args) {
  10.         Scanner scanner = new Scanner(System.in);
  11.         List<Integer> test = Arrays.stream(scanner.nextLine().split("\\s+")).
  12.                 map(Integer::parseInt).collect(Collectors.toList());
  13.         String command = scanner.nextLine();
  14.         int targets = 0;
  15.         while (!command.equals("End")) {
  16.             int index = Integer.parseInt(command);
  17.             if (index < test.size()) {
  18.                 int magic = test.get(index);
  19.                 for (int i = 0; i < test.size(); i++) {
  20.                     test.set(index, -1);
  21.                     if (test.get(i) >= 0 && test.get(i) <= magic) {
  22.                         test.set(i, test.get(i) + magic);
  23.  
  24.                     } else if (test.get(i) >= 0 && test.get(i) > magic) {
  25.                         test.set(i, test.get(i) - magic);
  26.                     }
  27.                 }
  28.                 targets++;
  29.             }
  30.             command = scanner.nextLine();
  31.         }
  32.         System.out.printf("Shot targets: %d -> ",targets);
  33.         for (Integer number : test) {
  34.             System.out.print(number + " ");
  35.         }
  36.     }
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment