Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package FundamentalsModule.ArraysExercises;
- import java.util.Arrays;
- import java.util.Scanner;
- public class LadyBugs {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int fieldSize = Integer.parseInt(scanner.nextLine());
- int[] field = new int[fieldSize];
- int[] ladyBugs = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
- for (int Bug : ladyBugs) {
- if (Bug >= 0 && Bug < field.length) {
- field[Bug] = 1;
- }
- }
- String input = scanner.nextLine();
- while (!input.equals("end")) {
- String[] command = input.split(" ");
- int insectIndex = Integer.parseInt(command[0]);
- String direction = command[1];
- int flyLength = Integer.parseInt(command[2]);
- if (insectIndex >= 0 && insectIndex < field.length && field[insectIndex] > 0 && flyLength != 0) { // Validaciq za index samo v ochertaniqta na kutiqta
- field[insectIndex] = 0;
- int flight = flyLength;
- switch (direction) {
- case "right":
- while (insectIndex + flight < field.length && insectIndex + flight >= 0 && field[insectIndex + flight] == 1) {
- flight++;
- }
- field[insectIndex + flight] = 1;
- break;
- case "left":
- while (insectIndex - flight >= 0 && insectIndex - flight < field.length && field[insectIndex - flight] == 1) {
- flight++;
- }
- field[insectIndex - flight] = 1;
- break;
- }
- }
- input = scanner.nextLine();
- }
- for(
- int index :
- field)
- {
- System.out.print(index + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement