SHARE
TWEET

Ladybugs

MartinGeorgiev Feb 18th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top