Sybatron

P03.Cooking Factory

Mar 2nd, 2019
193
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.Linq;
  3.  
  4. namespace P03CookingFactory
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int HighestTotalQuality = int.MinValue;
  11.             decimal HighestAvgQuality = decimal.MinValue;
  12.             int ShortestLenght = int.MaxValue;
  13.  
  14.             string BestBread = "";
  15.  
  16.             string input = Console.ReadLine();
  17.             if (input == "Bake It!")
  18.             {
  19.                 return;
  20.             }
  21.  
  22.             while (input != "Bake It!")
  23.             {
  24.                 int[] currentBreadBanch = input
  25.                     .Split('#', StringSplitOptions.RemoveEmptyEntries)
  26.                     .Select(int.Parse)
  27.                     .ToArray();
  28.  
  29.                 int SubTotalQuality = currentBreadBanch.Sum();
  30.                 decimal SubAvgQuality = SubTotalQuality / currentBreadBanch.Length * decimal.One;
  31.                 int SubShortestLenght = currentBreadBanch.Length;
  32.  
  33.                 if (SubTotalQuality > HighestTotalQuality)
  34.                 {
  35.                     HighestTotalQuality = SubTotalQuality;
  36.                     HighestAvgQuality = SubAvgQuality;
  37.                     ShortestLenght = SubShortestLenght;
  38.                     BestBread = string.Join(" ", currentBreadBanch);
  39.                 }
  40.                 else if (SubTotalQuality == HighestTotalQuality
  41.                     && SubAvgQuality > HighestAvgQuality)
  42.                 {
  43.                     HighestTotalQuality = SubTotalQuality;
  44.                     HighestAvgQuality = SubAvgQuality;
  45.                     ShortestLenght = SubShortestLenght;
  46.                     BestBread = string.Join(" ", currentBreadBanch);
  47.                 }
  48.                 else if (SubTotalQuality == HighestTotalQuality
  49.                     && SubAvgQuality == HighestAvgQuality
  50.                     && SubShortestLenght < ShortestLenght)
  51.                 {
  52.                     HighestTotalQuality = SubTotalQuality;
  53.                     HighestAvgQuality = SubAvgQuality;
  54.                     ShortestLenght = SubShortestLenght;
  55.                     BestBread = string.Join(" ", currentBreadBanch);
  56.                 }
  57.  
  58.                 input = Console.ReadLine();
  59.             }
  60.  
  61.             Console.WriteLine($"Best Batch quality: {HighestTotalQuality}");
  62.             Console.WriteLine(BestBread);
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment