Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Lekcii;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- public class ShootForTheWin {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] targetsStr = scanner.nextLine().split(" ");
- List<Integer> targets = new ArrayList<>();
- for (String targetStr : targetsStr) {
- targets.add(Integer.parseInt(targetStr));
- }
- int shotTargetsCount = 0;
- String input = scanner.nextLine();
- while (!input.equals("End")) {
- int index = Integer.parseInt(input);
- if (index >= 0 && index < targets.size() && targets.get(index) != -1) {
- int shotValue = targets.get(index);
- targets.set(index, -1);
- shotTargetsCount++;
- for (int i = 0; i < targets.size(); i++) {
- if (targets.get(i) != -1) {
- int currentValue = targets.get(i);
- if (currentValue > shotValue) {
- targets.set(i, currentValue - shotValue);
- } else if (currentValue <= shotValue) {
- targets.set(i, currentValue + shotValue);
- }
- }
- }
- }
- input = scanner.nextLine();
- }
- System.out.print("Shot targets: " + shotTargetsCount + " -> ");
- for (int i = 0; i < targets.size(); i++) {
- System.out.print(targets.get(i));
- if (i < targets.size() - 1) {
- System.out.print(" ");
- }
- }
- scanner.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement