Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Arrays;
- import java.util.Scanner;
- import java.util.Arrays;
- public class LadyBugs {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- int[] cells = new int[Integer.parseInt(sc.nextLine())];
- int[] indexes = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
- for (int i = 0; i < indexes.length; i++) {
- cells[indexes[i]] = 1;
- }
- String[] command = sc.nextLine().split(" ");
- int movePlus1 = 0;
- while (!"end".equalsIgnoreCase(command[0])) {
- int position = Integer.parseInt(command[0]);
- int move = Integer.parseInt(command[2]);
- if (cells[position] != 0 && move != 0 && command[1].equalsIgnoreCase("right")) {
- cells[position] = 0;
- while (true) {
- if (position + move + movePlus1 <= cells.length - 1 && cells[position + move + movePlus1] == 0 ) {
- cells[position + move + movePlus1] = 1;
- break;
- }else if (position + move + movePlus1 <= cells.length - 1 && cells[position + move] == 1) {
- movePlus1++;
- }else {
- break;
- }
- }
- } else if (cells[position] != 0 && move != 0 && command[1].equalsIgnoreCase("left")) {
- cells[position] = 0;
- while (true) {
- if (position - move - movePlus1 >= 0 && cells[position - move - movePlus1] == 0 ) {
- cells[position - move - movePlus1] = 1;
- break;
- }else if (position - move - movePlus1 >= 0 && cells[position - move] == 1) {
- movePlus1++;
- }else {
- break;
- }
- }
- }
- command = sc.nextLine().split(" ");
- movePlus1 = 0;
- }
- for (int i = 0; i < cells.length; i++) {
- System.out.print(cells[i] + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement