Advertisement
Guest User

LadyBugs

a guest
May 24th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.13 KB | None | 0 0
  1. package Arrays;
  2.  
  3. import java.util.Scanner;
  4. import java.util.Arrays;
  5.  
  6. public class LadyBugs {
  7.     public static void main(String[] args) {
  8.         Scanner sc = new Scanner(System.in);
  9.  
  10.         int[] cells = new int[Integer.parseInt(sc.nextLine())];
  11.         int[] indexes = Arrays.stream(sc.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
  12.  
  13.         for (int i = 0; i < indexes.length; i++) {
  14.             cells[indexes[i]] = 1;
  15.         }
  16.         String[] command = sc.nextLine().split(" ");
  17.         int movePlus1 = 0;
  18.         while (!"end".equalsIgnoreCase(command[0])) {
  19.             int position = Integer.parseInt(command[0]);
  20.             int move = Integer.parseInt(command[2]);
  21.             if (cells[position] != 0 && move != 0 && command[1].equalsIgnoreCase("right")) {
  22.                 cells[position] = 0;
  23.                 while (true) {
  24.                     if (position + move + movePlus1 <= cells.length - 1 && cells[position + move + movePlus1] == 0 ) {
  25.                         cells[position + move + movePlus1] = 1;
  26.                         break;
  27.                     }else if (position + move + movePlus1 <= cells.length - 1 && cells[position + move] == 1) {
  28.                         movePlus1++;
  29.                     }else {
  30.                         break;
  31.                     }
  32.                 }
  33.  
  34.             } else if (cells[position] != 0 && move != 0 && command[1].equalsIgnoreCase("left")) {
  35.                 cells[position] = 0;
  36.                 while (true) {
  37.                     if (position - move - movePlus1 >= 0 && cells[position - move - movePlus1] == 0 ) {
  38.                         cells[position - move - movePlus1] = 1;
  39.                         break;
  40.                     }else if (position - move - movePlus1 >= 0 && cells[position - move] == 1) {
  41.                         movePlus1++;
  42.                     }else {
  43.                         break;
  44.                     }
  45.                 }
  46.             }
  47.             command = sc.nextLine().split(" ");
  48.             movePlus1 = 0;
  49.         }
  50.         for (int i = 0; i < cells.length; i++) {
  51.             System.out.print(cells[i] + " ");
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement