Advertisement
Guest User

Untitled

a guest
Feb 9th, 2018
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.02 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 Juice_Diet
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int raspberry = int.Parse(Console.ReadLine());
  14.             int strawberry = int.Parse(Console.ReadLine());
  15.             int cherry = int.Parse(Console.ReadLine());
  16.             int juiceLimit = int.Parse(Console.ReadLine());
  17.             var total = 0.0;
  18.             var maxMl = 0.0;
  19.  
  20.             for (var R = 0; R <= raspberry ; R++)
  21.             {
  22.                 for (var S = 0; S <= strawberry ; S++)
  23.                 {
  24.                     for (var C = 0; C <= cherry; C++)
  25.                     {
  26.                         var raspML = R * 4.5;
  27.                         var strawML = S * 7.5;
  28.                         var cherryML = C * 15;
  29.                         total = raspML + strawML + cherryML;
  30.  
  31.                         if (total <= juiceLimit)
  32.                         {
  33.                             if (total > maxMl)
  34.                             {
  35.                                 maxMl = total;
  36.                             }
  37.                         }
  38.                        
  39.                     }
  40.                 }
  41.             }
  42.             for (var R = 0; R <= raspberry; R++)
  43.             {
  44.                 for (var S = 0; S <= strawberry; S++)
  45.                 {
  46.                     for (var C = 0; C <= cherry; C++)
  47.                     {
  48.                         var raspML = R * 4.5;
  49.                         var strawML = S * 7.5;
  50.                         var cherryML = C * 15;
  51.                         total = raspML + strawML + cherryML;
  52.  
  53.                         if (total == maxMl)
  54.                         {
  55.                             Console.WriteLine("{0} Raspberries, {1} Strawberries, {2} Cherries. Juice: {3} ml.", R, S, C, total);
  56.                             return;
  57.                         }
  58.                     }
  59.                 }
  60.             }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement