Advertisement
Guest User

Untitled

a guest
Mar 9th, 2019
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ConsoleApp2
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<int> bestBatch = new List<int>();
  12.             string command;
  13.             int quality = -1000000;
  14.  
  15.             while ((command=Console.ReadLine())!="Bake It!")
  16.             {
  17.                 List<int> currentBatch = command.Split("#").Select(int.Parse).ToList();
  18.                
  19.  
  20.                 if (quality < currentBatch.Sum())
  21.                 {
  22.                     quality = currentBatch.Sum();
  23.                     bestBatch = currentBatch;
  24.                 }
  25.                 else if (quality == currentBatch.Sum())
  26.                 {
  27.                     double averageForCurrentBestBatch = quality / bestBatch.Count;
  28.                     double averageForThisBatch = currentBatch.Sum() / currentBatch.Count;
  29.                     if (averageForThisBatch > averageForCurrentBestBatch)
  30.                     {
  31.                        
  32.                         bestBatch = currentBatch;
  33.                     }
  34.                     if (averageForCurrentBestBatch == averageForThisBatch)
  35.                     {
  36.                         if (currentBatch.Count<bestBatch.Count)
  37.                         {
  38.                             bestBatch = currentBatch;
  39.                         }
  40.                     }
  41.                 }
  42.             }
  43.             Console.WriteLine($"Best Batch quality: {quality}");
  44.             Console.WriteLine(string.Join(' ',bestBatch));
  45.  
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement