KrasimiraGeorgieva

06. Juice Diet, PB Online Exam - 7 January 2018

Feb 26th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.71 KB | None | 0 0
  1. <?php
  2. // Programming Basics Online Exam - 7 January 2018
  3.  
  4. $raspberries = intval(readline());
  5. $strawberries = intval(readline());
  6. $cherries = intval(readline());
  7. $juiceCapacity = intval(readline());
  8.  
  9. $result = '';
  10. $maxJuice = -1;
  11.  
  12. for ($n3 = $cherries; $n3 >= 0; $n3--) {
  13.     for ($n2 = $strawberries; $n2 >= 0; $n2--) {
  14.         for ($n1 = $raspberries; $n1 >= 0; $n1--) {
  15.             $currentJuice = $n1 * 4.5 + $n2 * 7.5 + $n3 * 15;
  16.             if ($currentJuice <= $juiceCapacity && $maxJuice < $currentJuice) {
  17.                 $maxJuice = $currentJuice;
  18.                 $result = "$n1 Raspberries, $n2 Strawberries, $n3 Cherries. Juice: $maxJuice ml.";
  19.             }
  20.         }
  21.     }
  22. }
  23.  
  24. echo $result;
Add Comment
Please, Sign In to add comment