Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package MoreExercise;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- List<Integer> targets = new ArrayList<>();
- String[] initialTargets = scanner.nextLine().split(" ");
- for (String target : initialTargets) {
- targets.add(Integer.parseInt(target));
- }
- while (true) {
- String input = scanner.nextLine();
- if (input.equals("End")) {
- break;
- }
- String[] commandInput = input.split(" ");
- String command = commandInput[0];
- int index = Integer.parseInt(commandInput[1]);
- if (command.equals("Shoot")) {
- int power = Integer.parseInt(commandInput[2]);
- if (index >= 0 && index < targets.size()) {
- targets.set(index, targets.get(index) - power);
- if (targets.get(index) <= 0) {
- targets.remove(index);
- }
- }
- } else if (command.equals("Add")) {
- int value = Integer.parseInt(commandInput[2]);
- if (index >= 0 && index < input.length()) {
- targets.add(index, value);
- } else {
- System.out.println("Invalid placement!");
- }
- } else if (command.equals("Strike")) {
- int radius = Integer.parseInt(commandInput[2]);
- if (index - radius >= 0 && index + radius < targets.get(targets.size() - 1)) {
- targets.subList(index - radius, index + radius + 1).clear();
- } else {
- System.out.println("Strike missed!");
- }
- }
- }
- for (int i = 0; i < targets.size(); i++) {
- System.out.print(targets.get(i));
- if (i != targets.size() - 1) {
- System.out.print("|");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement