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];
- int[] positions = Arrays.stream(sc.nextLine().split(" "))
- .mapToInt(Integer::parseInt).toArray();
- 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];
- if (indexLadyBug >=0 && indexLadyBug < field.length && flyDestination != 0) {
- switch (direction) {
- case "right":
- int newPosition = indexLadyBug + flyDestination;
- if(newPosition < field.length && newPosition >= 0) {
- if (field[indexLadyBug] == 1 && field[newPosition] == 0) {
- field[indexLadyBug] = 0;
- field[newPosition] = 1;
- }else if (field[indexLadyBug] == 1 && field[flyDestination] == 1) {
- for (int i = flyDestination * 2; true; i += flyDestination) {
- if (i > field.length - 1) {
- field[indexLadyBug] = 0;
- break;
- }else if (field[i] == 0) {
- field[i] = 1;
- field[indexLadyBug] = 0;
- break;
- }
- }
- }
- }else {
- field[indexLadyBug] = 0;
- }
- break;
- case "left":
- int newPositionLeft = indexLadyBug - flyDestination;
- if(newPositionLeft >= 0 && newPositionLeft < field.length) {
- if(field[indexLadyBug] == 1 && field[newPositionLeft] == 0) {
- field[indexLadyBug] = 0;
- field[newPositionLeft] = 1;
- }else if(field[indexLadyBug] == 1 && field[flyDestination] == 1) {
- for (int i = flyDestination * 2; true; i -= flyDestination) {
- if (i < 0) {
- field[indexLadyBug] = 0;
- break;
- }else if(field[i] == 0) {
- field[i] = 1;
- field[indexLadyBug] = 0;
- break;
- }
- }
- }
- }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