NastySwipy

Exam - 7 January 2018 - 06. Juice Diet(F)

Feb 26th, 2018
128
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. $raspberries = intval(readline());
  3. $strawberries = intval(readline());
  4. $cherries = intval(readline());
  5. $juice = intval(readline());
  6. $cherriesUsed = 0;
  7. $strawberriesUsed = 0;
  8. $raspberriesUsed = 0;
  9. $juiceTotal = floatval(0.0);
  10. for ($i = 0; $i <= $cherries; $i++) {
  11.     for ($j = 0; $j <= $strawberries; $j++) {
  12.         for ($k = 0; $k <= $raspberries; $k++) {
  13.             $juiceCurrent = floatval($i * 15 + $j * 7.5 + $k * 4.5);
  14.             if ($juiceCurrent <= $juice) {
  15.                 if ($juiceCurrent > $juiceTotal) {
  16.                     $juiceTotal = $juiceCurrent;
  17.                 }
  18.                 if ($juiceCurrent >= $juiceTotal) {
  19.                     $cherriesUsed = $i;
  20.                     $strawberriesUsed = $j;
  21.                     $raspberriesUsed = $k;
  22.                 }
  23.             }
  24.         }
  25.     }
  26. }
  27. echo $raspberriesUsed . " Raspberries, " . $strawberriesUsed
  28.  . " Strawberries, " . $cherriesUsed . " Cherries."
  29.  . " Juice: " . $juiceTotal . " ml.";
Add Comment
Please, Sign In to add comment