ShadowEmbrace

Bomb Number

Nov 4th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.98 KB | None | 0 0
  1. <?php
  2.  
  3. $numbers = array_map('intval', explode(' ', readline()));
  4. $bombNumbers = array_map('intval', explode(' ', readline()));
  5.  
  6. for ($i = 0; $i < count($numbers); $i++) {
  7.     if ($numbers[$i] === $bombNumbers[0]) {
  8.         if ($bombNumbers[1] + $i >= count($numbers)) {
  9.             array_splice($numbers, $i, count($numbers) - $i);
  10.             array_splice($numbers, $i - $bombNumbers[1], $bombNumbers[1]);
  11.             break;
  12.         }
  13.         if ($i - $bombNumbers[1] < 0) {
  14.             if ($i === 0) {
  15.                 array_splice($numbers, 0, 1 + $bombNumbers[1]);
  16.                 $i = -1;
  17.             } else {
  18.                 array_splice($numbers, 0, $i);
  19.                 array_splice($numbers, $i + 1, $bombNumbers[1] - 1);
  20.                 $i -= $bombNumbers[1] + 1;
  21.             }
  22.         } else {
  23.             array_splice($numbers, $i - $bombNumbers[1], ($bombNumbers[1] * 2) + 1);
  24.             $i -= $bombNumbers[1] + 1;
  25.         }
  26.     }
  27. }
  28.  
  29. echo array_sum($numbers);
Add Comment
Please, Sign In to add comment