Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Demo {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int[] targets = Arrays.stream(scan.nextLine().split("\\s+")).mapToInt(Integer::parseInt).toArray();
- int successfullShots = 0;
- String input = scan.nextLine();
- while (!input.equals("End")) {
- int index = Integer.parseInt(input);
- if (index < targets.length) {
- int num = targets[index];
- targets[index] = -1;
- successfullShots++;
- for (int i = 0; i < targets.length; i++) {
- if (i != index) {
- if (targets[i] > num) {
- targets[i] -= num;
- } else if (targets[i] != -1) {
- targets[i] += num;
- }
- }
- }
- }
- input = scan.nextLine();
- }
- System.out.print(String.format("Shot targets: %d -> ", successfullShots));
- for (int target : targets) {
- System.out.print(target + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement