Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace P03CookingFactory
- {
- class Program
- {
- static void Main(string[] args)
- {
- double bestQuality = 0;
- int bestLength = 0;
- int bestIndex = 0;
- double bestAverage = 0;
- double tempQuality = 0;
- int tempLength = 0;
- int tempIndex = 0;
- double tempAverage = 0;
- List<List<int>> batches = new List<List<int>>();
- List<int> tempList = new List<int>();
- List<int> numbersList = new List<int>();
- List<int> bestBatch = new List<int>();
- List<int> tempBestBatch = new List<int>();
- while (true)
- {
- string command = Console.ReadLine();
- if (command=="Bake It!")
- {
- break;
- }
- string[] tokens = command.Split("#");
- int element = 0;
- for(int i = 0; i < tokens.Length; i++)
- {
- element = int.Parse(tokens[i]);
- tempList.Add(element);
- }
- batches.Add(tempList);
- tempList.Clear();
- }
- for (int i = 0; i < batches.Count; i++)
- {
- tempQuality = batches[i].Sum();
- tempLength = batches[i].Count();
- tempIndex = batches.IndexOf(batches[i]);
- tempAverage = tempQuality / tempLength;
- if (tempQuality > bestQuality)
- {
- bestQuality = tempQuality;
- bestLength = tempLength;
- bestAverage = tempAverage;
- bestIndex = tempIndex; //!!
- }
- else if (tempQuality == bestQuality)
- {
- if (tempAverage > bestAverage)
- {
- bestIndex = tempIndex;
- }
- else if (tempAverage == bestAverage)
- {
- if (tempLength < bestLength)
- {
- bestIndex = tempIndex;
- }
- }
- }
- }
- Console.WriteLine($"Best Batch quality: {bestQuality}");
- Console.WriteLine(String.Join(" ", batches[bestIndex]));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement