Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.List;
- import java.util.Scanner;
- import java.util.stream.Collectors;
- public class ShootForTheWin {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- List<Integer> targets = Arrays.stream(sc.nextLine().split("\\s+")).map(Integer::parseInt).collect(Collectors.toList());
- int count = 0;
- String n;
- while (!"End".equals(n = sc.nextLine())){
- int shot = Integer.parseInt(n);
- if (shot < targets.size() && shot >= 0) {
- int actualTarget = targets.get(shot);
- if (actualTarget != -1) {
- targets.set(shot, -1);
- count++;
- }
- for (int i = 0; i < targets.size(); i++) {
- if (targets.get(i) != -1) {
- if (targets.get(i) <= actualTarget) {
- targets.set(i, targets.get(i) + actualTarget);
- } else {
- targets.set(i, targets.get(i) - actualTarget);
- }
- }
- }
- }
- }
- System.out.printf("Shot targets: %d -> %s", count, targets.toString().replaceAll("[\\[\\],]", ""));
- }
- }
Add Comment
Please, Sign In to add comment