nikolayneykov

Untitled

Mar 3rd, 2019
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.28 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. class Program
  5. {
  6.     static void Main(string[] args)
  7.     {
  8.         int[] bestBatch = new int[] { int.MinValue };
  9.         int bestQuality = int.MinValue;                
  10.         string input = string.Empty;
  11.  
  12.         while ((input = Console.ReadLine()) != "Bake It!")
  13.         {
  14.             int[] currentBatch = input.Split('#').Select(int.Parse).ToArray(); //настоящата партида
  15.             int currentQuality = currentBatch.Sum();                           //настоящото качество
  16.             bool foundBetterBatch = false;       //булева променлива за това дали сме намерили по-добра партида
  17.  
  18.             if (bestQuality < currentQuality)    //проверка по първи критерий (ако сумата на най-добрата партида е по малка от сумата на настоящата)
  19.             {
  20.                 foundBetterBatch = true;
  21.             }
  22.             else if (bestQuality == currentQuality)                        //при равно качество
  23.             {
  24.                 if (bestBatch.Average() < currentBatch.Average())          //втори критерий сравняваме средноаритметичните суми
  25.                 {
  26.                     foundBetterBatch = true;
  27.                 }
  28.                 else if (bestBatch.Average() == currentBatch.Average() &&  //при равни средноаритметични суми
  29.                          bestBatch.Length > currentBatch.Length)           //сравняваме по трети критерий (дължина на партидите)
  30.                 {
  31.                     foundBetterBatch = true;
  32.                 }
  33.             }
  34.  
  35.             if (foundBetterBatch)                          //ако е намерена по-добра партида
  36.             {
  37.                 bestBatch = (int[])currentBatch.Clone();   //най-добрата ни партида става настоящата
  38.                 bestQuality = bestBatch.Sum();             //ъпдейтваме bestQuality
  39.             }
  40.         }
  41.  
  42.         Console.WriteLine($"Best Batch quality: {bestQuality}\n{string.Join(" ", bestBatch)}");
  43.     }
  44. }
Add Comment
Please, Sign In to add comment