Advertisement
Ligh7_of_H3av3n

ShootForTheWin

Feb 14th, 2024
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.70 KB | None | 0 0
  1. package Lekcii;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Scanner;
  6.  
  7. public class ShootForTheWin {
  8.     public static void main(String[] args) {
  9.         Scanner scanner = new Scanner(System.in);
  10.  
  11.         String[] targetsStr = scanner.nextLine().split(" ");
  12.         List<Integer> targets = new ArrayList<>();
  13.         for (String targetStr : targetsStr) {
  14.             targets.add(Integer.parseInt(targetStr));
  15.         }
  16.  
  17.         int shotTargetsCount = 0;
  18.  
  19.         String input = scanner.nextLine();
  20.         while (!input.equals("End")) {
  21.             int index = Integer.parseInt(input);
  22.  
  23.             if (index >= 0 && index < targets.size() && targets.get(index) != -1) {
  24.                 int shotValue = targets.get(index);
  25.                 targets.set(index, -1);
  26.                 shotTargetsCount++;
  27.  
  28.                 for (int i = 0; i < targets.size(); i++) {
  29.                     if (targets.get(i) != -1) {
  30.                         int currentValue = targets.get(i);
  31.                         if (currentValue > shotValue) {
  32.                             targets.set(i, currentValue - shotValue);
  33.                         } else if (currentValue <= shotValue) {
  34.                             targets.set(i, currentValue + shotValue);
  35.                         }
  36.                     }
  37.                 }
  38.             }
  39.  
  40.             input = scanner.nextLine();
  41.         }
  42.  
  43.         System.out.print("Shot targets: " + shotTargetsCount + " -> ");
  44.         for (int i = 0; i < targets.size(); i++) {
  45.             System.out.print(targets.get(i));
  46.             if (i < targets.size() - 1) {
  47.                 System.out.print(" ");
  48.             }
  49.         }
  50.  
  51.         scanner.close();
  52.     }
  53. }
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement