Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace _03BakingFactory
- {
- class Program
- {
- static void Main(string[] args)
- {
- double currQuality = 0;
- double bestQuality = double.MinValue;
- double currAvg = 0;
- double bestAvg = double.MinValue;
- int currLen = -1;
- int bestLen = int.MaxValue;
- List<int> bestBatch = new List<int>();
- while (true)
- {
- string command = Console.ReadLine();
- if (command == "Bake It!")
- {
- break;
- }
- currQuality = 0;
- currAvg = 0;
- int[] currBatch = command.Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- for (int i = 0; i < currBatch.Length; i++)
- {
- currQuality += currBatch[i];
- }
- currAvg = currQuality / currBatch.Length;
- currLen = currBatch.Length;
- if (currQuality > bestQuality)
- {
- bestQuality = currQuality;
- bestBatch.Clear();
- bestBatch.AddRange(currBatch);
- bestAvg = currAvg;
- bestLen = currLen;
- }
- else if (currQuality == bestQuality)
- {
- if (currAvg > bestAvg)
- {
- bestQuality = currQuality;
- bestBatch.Clear();
- bestBatch.AddRange(currBatch);
- }
- else if (currAvg == bestAvg)
- {
- if (currLen < bestLen)
- {
- bestQuality = currQuality;
- bestBatch.Clear();
- bestBatch.AddRange(currBatch);
- }
- }
- }
- }
- Console.WriteLine("Best Batch quality: {0}", bestQuality);
- Console.WriteLine(string.Join(" ", bestBatch));
- }
- }
- }
Add Comment
Please, Sign In to add comment