Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Scanner;
- public class kur {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int sizeField = Integer.parseInt(sc.nextLine());
- int[] field = new int[sizeField];
- String ladybugs = sc.nextLine();
- String[] ladybugPositions = ladybugs.split(" ");
- int[] positions = new int[ladybugPositions.length];
- for (int j = 0; j < ladybugPositions.length; j++) {
- positions[j] = Integer.parseInt(ladybugPositions[j]);
- }
- for (int i = 0; i < positions.length; i++) {
- if (positions[i] < field.length && positions[i] >= 0) {
- field[positions[i]] = 1;
- }
- }
- String input = sc.nextLine();
- String[] arrayedInput = input.split(" ");
- while (!"end".equals(input)) {
- int indexLadyBug = Integer.parseInt(arrayedInput[0]);
- int flyDestination = Integer.parseInt(arrayedInput[2]);
- String direction = arrayedInput[1];
- switch (direction) {
- case "right":
- int newPosition = indexLadyBug + flyDestination;
- if (newPosition > field.length - 1) {
- field[indexLadyBug] = 0;
- }else if (field[newPosition] == 0 && field[indexLadyBug] == 1) {
- field[indexLadyBug] = 0;
- field[newPosition] = 1;
- }else if (field[newPosition] == 1 && field[indexLadyBug] == 1){
- for (int i = newPosition; true; i += flyDestination) {
- if (i > field.length - 1) {
- field[indexLadyBug] = 0;
- break;
- }else if (field[i] == 0) {
- field[indexLadyBug] = 0;
- field[i] = 1;
- }
- }
- }else {
- field[indexLadyBug] = 0;
- }
- break;
- case "left":
- int newPositionLeft = indexLadyBug - flyDestination;
- if (newPositionLeft < 0) {
- field[indexLadyBug] = 0;
- }else if (field[newPositionLeft] == 0 && field[indexLadyBug] == 1) {
- field[indexLadyBug] = 0;
- field[newPositionLeft] = 1;
- }else if (field[newPositionLeft] == 1){
- for (int i = indexLadyBug - flyDestination * 2; true; i -= flyDestination) {
- if (indexLadyBug - i < 0) {
- field[indexLadyBug] = 0;
- break;
- }else if (field[i] == 0) {
- field[indexLadyBug] = 0;
- field[i] = 1;
- }
- }
- }else {
- field[indexLadyBug] = 0;
- }
- break;
- default:
- break;
- }
- input = sc.nextLine();
- arrayedInput = input.split(" ");
- }
- for (int bugs:field) {
- System.out.print(bugs + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement