Advertisement
kristina111

Untitled

Feb 6th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.65 KB | None | 0 0
  1. <?php
  2. $input=fgets(STDIN);
  3. $arrayInput=explode(" ",$input);
  4. $lenArr=count($arrayInput);
  5. $leftSum=0;
  6. $rightSum=0;
  7.  
  8.  
  9. for($i=0; $i < $lenArr; $i++) {
  10.     for ($right = $i + 1; $right < $lenArr; $right++) {
  11.         $rightSum += $arrayInput[$right];
  12.     }
  13. //    echo "{$rightSum}\n";
  14.     for ($left = 0; $left <=$i-1; $left++) {
  15.         if ($i == 0) {
  16.             break;
  17.         } else {
  18.             $leftSum += $arrayInput[$left];
  19.  
  20.         }
  21.     }
  22. //    echo "{$leftSum}\n";
  23.     if ($rightSum == $leftSum) {
  24.         echo $i;
  25.         return;
  26.     }
  27.  
  28.     $leftSum=0;
  29.     $rightSum=0;
  30. //    else{
  31. //        echo "no";
  32. //    }
  33. }
  34. echo "no";
  35. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement