Advertisement
Guest User

Untitled

a guest
Feb 9th, 2019
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.46 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4. public class kur {
  5.     public static void main(String[] args) {
  6.  
  7.         Scanner sc = new Scanner(System.in);
  8.  
  9.         int sizeField = Integer.parseInt(sc.nextLine());
  10.         int[] field = new int[sizeField];
  11.  
  12.         String ladybugs = sc.nextLine();
  13.         String[] ladybugPositions = ladybugs.split(" ");
  14.         int[] positions = new int[ladybugPositions.length];
  15.  
  16.         for (int j = 0; j < ladybugPositions.length; j++) {
  17.             positions[j] = Integer.parseInt(ladybugPositions[j]);
  18.  
  19.         }
  20.  
  21.  
  22.         for (int i = 0; i < positions.length; i++) {
  23.  
  24.             if (positions[i] < field.length && positions[i] >= 0) {
  25.                 field[positions[i]] = 1;
  26.             }
  27.  
  28.  
  29.         }
  30.  
  31.         String input = sc.nextLine();
  32.         String[] arrayedInput = input.split(" ");
  33.  
  34.         while (!"end".equals(input)) {
  35.  
  36.             int indexLadyBug = Integer.parseInt(arrayedInput[0]);
  37.             int flyDestination = Integer.parseInt(arrayedInput[2]);
  38.             String direction = arrayedInput[1];
  39.  
  40.             switch (direction) {
  41.                 case "right":
  42.  
  43.                     int newPosition = indexLadyBug + flyDestination;
  44.  
  45.                     if (newPosition > field.length - 1) {
  46.                         field[indexLadyBug] = 0;
  47.                     }else if (field[newPosition] == 0 && field[indexLadyBug] == 1) {
  48.                         field[indexLadyBug] = 0;
  49.                         field[newPosition] = 1;
  50.                     }else if (field[newPosition] == 1 && field[indexLadyBug] == 1){
  51.                         for (int i = newPosition; true; i += flyDestination) {
  52.                             if (i > field.length - 1) {
  53.                                 field[indexLadyBug] = 0;
  54.                                 break;
  55.                             }else if (field[i] == 0) {
  56.                                 field[indexLadyBug] = 0;
  57.                                 field[i] = 1;
  58.                             }
  59.                         }
  60.                     }else {
  61.                         field[indexLadyBug] = 0;
  62.                     }
  63.                     break;
  64.  
  65.                 case "left":
  66.  
  67.                     int newPositionLeft = indexLadyBug - flyDestination;
  68.  
  69.                     if (newPositionLeft < 0) {
  70.                         field[indexLadyBug] = 0;
  71.                     }else if (field[newPositionLeft] == 0 && field[indexLadyBug] == 1) {
  72.                         field[indexLadyBug] = 0;
  73.                         field[newPositionLeft] = 1;
  74.                     }else if (field[newPositionLeft] == 1){
  75.                         for (int i = indexLadyBug - flyDestination * 2; true; i -= flyDestination) {
  76.                             if (indexLadyBug - i < 0) {
  77.                                 field[indexLadyBug] = 0;
  78.                                 break;
  79.                             }else if (field[i] == 0) {
  80.                                 field[indexLadyBug] = 0;
  81.                                 field[i] = 1;
  82.                             }
  83.                         }
  84.                     }else {
  85.                         field[indexLadyBug] = 0;
  86.                     }
  87.                     break;
  88.  
  89.                     default:
  90.                         break;
  91.             }
  92.  
  93.  
  94.             input = sc.nextLine();
  95.             arrayedInput = input.split(" ");
  96.         }
  97.  
  98.         for (int bugs:field) {
  99.             System.out.print(bugs + " ");
  100.  
  101.         }
  102.     }
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement