Advertisement
kallyy7

Untitled

Feb 28th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _06.JuiceDiet
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int r = int.Parse(Console.ReadLine());
  14.             int s = int.Parse(Console.ReadLine());
  15.             int c = int.Parse(Console.ReadLine());
  16.             int juiceMax = int.Parse(Console.ReadLine());
  17.             double max = 0;
  18.             int maxRasp = 0;
  19.             int maxStraw = 0;
  20.             int maxCherries = 0;
  21.             for (int ras = 0; ras <= r; ras++)
  22.             {
  23.                 for (int str = 0; str <= s; str++)
  24.                 {
  25.                     for (int che = 0; che <= c; che++)
  26.                     {
  27.                         double cherries = 15 * che;
  28.                         double strawberries = 7.5 * str;
  29.                         double raspberries = 4.5 * ras;
  30.                         double juice = raspberries + strawberries + cherries;
  31.                         if (juice <= juiceMax)
  32.                         {
  33.                             if (juice > max)
  34.                             {
  35.                                 maxRasp = ras;
  36.                                 maxStraw = str;
  37.                                 maxCherries = che;
  38.                                 max = juice;
  39.                             }
  40.                         }
  41.                         if (juice == juiceMax || juice == juiceMax - 1)
  42.                         {
  43.                             if (cherries > strawberries && cherries > raspberries || strawberries > raspberries)
  44.                             {
  45.                                 Console.WriteLine($"{ras} Raspberries, {str} Strawberries, {che} Cherries. Juice: {juice} ml.");
  46.                                 return;
  47.                             }
  48.                             else
  49.                             {
  50.                                 Console.WriteLine($"{ras} Raspberries, {str} Strawberries, {che} Cherries. Juice: {juice} ml.");
  51.                                 return;
  52.                             }
  53.                         }      
  54.                     }
  55.                 }
  56.             }
  57.             Console.WriteLine($"{maxRasp} Raspberries, {maxStraw} Strawberries, {maxCherries} Cherries. Juice: {max} ml.");
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement