Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $raspberries = intval(readline());
- $strawberries = intval(readline());
- $cherries = intval(readline());
- $juice = intval(readline());
- $cherriesUsed = 0;
- $strawberriesUsed = 0;
- $raspberriesUsed = 0;
- $juiceTotal = floatval(0.0);
- for ($i = 0; $i <= $cherries; $i++) {
- for ($j = 0; $j <= $strawberries; $j++) {
- for ($k = 0; $k <= $raspberries; $k++) {
- $juiceCurrent = floatval($i * 15 + $j * 7.5 + $k * 4.5);
- if ($juiceCurrent <= $juice) {
- if ($juiceCurrent > $juiceTotal) {
- $juiceTotal = $juiceCurrent;
- }
- if ($juiceCurrent >= $juiceTotal) {
- $cherriesUsed = $i;
- $strawberriesUsed = $j;
- $raspberriesUsed = $k;
- }
- }
- }
- }
- }
- echo $raspberriesUsed . " Raspberries, " . $strawberriesUsed
- . " Strawberries, " . $cherriesUsed . " Cherries."
- . " Juice: " . $juiceTotal . " ml.";
Add Comment
Please, Sign In to add comment