Advertisement
Guest User

04. Balls PHP

a guest
Mar 13th, 2018
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.91 KB | None | 0 0
  1. <?php
  2. $numOfBalls = intval(readline());
  3. $points = 0;
  4. $red = 0;
  5. $orange = 0;
  6. $yellow = 0;
  7. $white = 0;
  8. $black = 0;
  9. $other = 0;
  10.  
  11. for($i=1; $i <= $numOfBalls;$i++){
  12.    $ballColor = strtolower(readline());
  13.     if($ballColor == "red"){
  14.         $red++;
  15.         $points += 5;
  16.     }elseif ($ballColor == "orange"){
  17.         $orange++;
  18.         $points += 10;
  19.     }elseif ($ballColor == "yellow"){
  20.         $yellow++;
  21.         $points += 15;
  22.     }elseif ($ballColor == "white"){
  23.         $white++;
  24.         $points += 20;
  25.     }elseif ($ballColor == "black"){
  26.         $black++;
  27.         $points /= 2;
  28.     }else{
  29.         $other ++;
  30.     }
  31. }
  32.  
  33. printf("Total points: %.0f\nPoints from red balls: %.0f\nPoints from orange balls: %.0f\nPoints from yellow balls: %.0f\nPoints from white balls: %.0f\nOther colors picked: %.0f\nDivides from black balls: %.0f",
  34.     floor($points),$red,$orange,$yellow,$white,$other,$black);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement