using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace wormsworldpartyizpit30april { class Program { static void Main(string[] args) { Dictionary> wormsParty = new Dictionary>(); bool exist = false; string input = Console.ReadLine(); List names = new List(); while (input != "quit") { string[] inputTokens = input.Split(new string[] {" -> "}, StringSplitOptions.RemoveEmptyEntries).ToArray(); string name = inputTokens[0]; string team = inputTokens[1]; long score = long.Parse(inputTokens[2]); if (names.Contains(name)) { exist = true; } if (!exist) { if (!wormsParty.ContainsKey(team)) { wormsParty.Add(team, new Dictionary()); } wormsParty[team].Add(name, score); names.Add(name); } input = Console.ReadLine(); } // logic done output left! wormsParty= wormsParty.OrderByDescending(x => x.Value.Sum(y => y.Value)) .ThenByDescending(x => x.Value.Sum(y => y.Value) / x.Value.Count()) .ToDictionary(x => x.Key, x => x.Value); int count = 1; foreach (KeyValuePair> pair in wormsParty) { string team = pair.Key; Dictionary worms = pair.Value; long total = worms.Values.Sum(); Console.WriteLine($"{count}. Team: {team} - {total}"); foreach (KeyValuePair kvp in worms.OrderByDescending(x=>x.Value)) { Console.WriteLine($"###{kvp.Key} : {kvp.Value}"); } count++; } } } }