Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Programming Basics Online Exam - 7 January 2018
- $raspberries = intval(readline());
- $strawberries = intval(readline());
- $cherries = intval(readline());
- $juiceCapacity = intval(readline());
- $result = '';
- $maxJuice = -1;
- for ($n3 = $cherries; $n3 >= 0; $n3--) {
- for ($n2 = $strawberries; $n2 >= 0; $n2--) {
- for ($n1 = $raspberries; $n1 >= 0; $n1--) {
- $currentJuice = $n1 * 4.5 + $n2 * 7.5 + $n3 * 15;
- if ($currentJuice <= $juiceCapacity && $maxJuice < $currentJuice) {
- $maxJuice = $currentJuice;
- $result = "$n1 Raspberries, $n2 Strawberries, $n3 Cherries. Juice: $maxJuice ml.";
- }
- }
- }
- }
- echo $result;
Add Comment
Please, Sign In to add comment