Advertisement
Spocoman

Juice Diet

Oct 9th, 2023
866
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main() {  
  6.     int r, s, c, maxJuice;
  7.     cin >> r >> s >> c >> maxJuice;
  8.  
  9.     double juice = 0;
  10.     int raspberries = 0, strawberries = 0, cherries = 0;
  11.  
  12.     for (int j = 0; j <= r; j++) {
  13.         for (int k = 0; k <= s; k++) {
  14.             for (int l = 0; l <= c; l++) {
  15.                 double currentJuice = 4.5 * j + 7.5 * k + 15 * l;
  16.                 if (juice < currentJuice && currentJuice <= maxJuice) {
  17.                     juice = currentJuice;
  18.                     raspberries = j;
  19.                     strawberries = k;
  20.                     cherries = l;
  21.                 }
  22.             }
  23.         }
  24.     }
  25.    
  26.     cout << raspberries << " Raspberries, " << strawberries << " Strawberries, " << cherries << " Cherries. Juice: " << juice << " ml.\n";
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement