Advertisement
MartinGeorgiev

Ladybugs

Feb 18th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.96 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. $size=intval(readline());
  5. $indexes=array_map('intval',explode(' ',readline()));
  6. $commands='';
  7. $arr=[];
  8. for($i=0;$i<$size;$i++){
  9.  
  10.                 if (in_array($i,$indexes))
  11.                 {
  12.                     $arr[$i] = 1;
  13.                 }else{
  14.                     $arr[$i]=0;
  15.                 }
  16.  
  17. }
  18.  
  19. while(($commands=readline())!=='end') {
  20.     $commands = explode(' ', $commands);
  21.     // print_r($commands);
  22.     $index = intval($commands[0]);
  23.  
  24.  
  25.     $direction = $commands[1] === "left" ? -1 : 1;
  26.     $steps = intval($commands[2])*$direction;
  27.                 if ($index < 0 || $index >= $size || !$arr[$index])
  28.                     continue;
  29.                 $arr[$index] =0;
  30.                 while (($index += $steps) >= 0 && $index < $size)
  31.                 {
  32.                     if ($arr[$index]) continue;
  33.                     $arr[$index] = 1;
  34.                     break;
  35.                 }
  36.             }
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43. echo implode(' ',$arr);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement