Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. <?php
  2.  
  3. $n = intval(readline());
  4.  
  5. $arr = explode(' ', readline());
  6.  
  7. $cells = [];
  8.  
  9. for ($i = 0; $i < $n; $i++)
  10. {
  11. $cells[$i] = 0;
  12. }
  13.  
  14. for ($i = 0; $i < count($arr); $i++)
  15. {
  16. if (array_key_exists($arr[$i], $cells))
  17. {
  18. $cells[$arr[$i]] = 1;
  19. }
  20. }
  21.  
  22. ksort($cells);
  23.  
  24. $command = readline();
  25.  
  26. while ($command != 'end')
  27. {
  28. $c = explode(' ', $command);
  29.  
  30. if ($c[1] == 'right' && array_key_exists($c[0], $cells) && $cells[$c[0]] == 1)
  31. {
  32. if (array_key_exists($c[0] + $c[2], $cells))
  33. {
  34. for ($i = $c[0] + $c[2]; $i < count($cells); $i++)
  35. {
  36. if ($cells[$i] == 0)
  37. {
  38. $cells[$i] = 1;
  39. break;
  40. }
  41. }
  42. }
  43. }
  44. elseif ($c[1] == 'left' && array_key_exists($c[0], $cells) && $cells[$c[0]] == 1)
  45. {
  46. if (array_key_exists($c[0] - $c[2], $cells))
  47. {
  48. for ($i = $c[0] - $c[2]; $i >= 0; $i--)
  49. {
  50. if ($cells[$i] == 0)
  51. {
  52. $cells[$i] = 1;
  53. break;
  54. }
  55. }
  56. }
  57. }
  58. if (array_key_exists($c[0], $cells))
  59. {
  60. $cells[$c[0]] = 0;
  61. }
  62. $command = readline();
  63. }
  64.  
  65. echo implode(' ', $cells);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement