deleriumbg

Juice Diet

Apr 5th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Juice_Diet
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int raspberryMax = int.Parse(Console.ReadLine());
  10.             int strawberryMax = int.Parse(Console.ReadLine());
  11.             int cherryMax = int.Parse(Console.ReadLine());
  12.             int juiceAllowed = int.Parse(Console.ReadLine());
  13.  
  14.             double juiceMax = 0;
  15.             int raspberry = 0;
  16.             int strawberry = 0;
  17.             int cherry = 0;
  18.             for (int i = 0; i <= cherryMax; i++)
  19.             {
  20.                 for (int j = 0; j <= strawberryMax; j++)
  21.                 {
  22.                     for (int k = 0; k <= raspberryMax; k++)
  23.                     {
  24.                         double currentJuice = 15 * i + 7.5 * j + 4.5 * k;
  25.                         if (currentJuice <= juiceAllowed)
  26.                         {
  27.                             if (currentJuice >= juiceMax)
  28.                             {
  29.                                 juiceMax = currentJuice;
  30.                                 cherry = i;
  31.                                 strawberry = j;
  32.                                 raspberry = k;
  33.                             }
  34.                         }
  35.                     }
  36.                 }
  37.             }
  38.             Console.WriteLine($"{raspberry} Raspberries, {strawberry} Strawberries, {cherry} Cherries. Juice: {juiceMax} ml.");
  39.         }
  40.     }
  41. }
Add Comment
Please, Sign In to add comment