Advertisement
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 _05_BombMimi {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- List<String> numbers = Arrays.stream(scanner.nextLine()
- .split("\\s+"))
- .collect(Collectors.toList());
- String bomb = scanner.next();
- int power = Integer.parseInt(scanner.next());
- while (numbers.contains(bomb)) {
- int index = numbers.indexOf(bomb); // Като завърти сл.итерация да вземе актуалния индекс...
- int left = Math.max(0, index - power);
- int right = Math.min(index + power, numbers.size() - 1);
- for (int i = right; i >= left; i--) { //Обратен цикъл, за да не премества индекси...
- numbers.remove(i);
- }
- }
- int sum = 0;
- for (String number : numbers) {
- int num = Integer.parseInt(number); //парсва се, за да можем да изчисляваме...
- sum += num;
- }
- System.out.println(sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement