static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); Dictionary <string, List <Dragon> > dragons = new Dictionary <string, List <Dragon> >(); for (int i = 0; i < n; i++) { string[] tokens = Console.ReadLine().Split(); string type = tokens[0]; string name = tokens[1]; int damage = tokens[2] == "null" ? 45 : int.Parse(tokens[2]); int health = tokens[3] == "null" ? 250 : int.Parse(tokens[3]); int armor = tokens[4] == "null" ? 10 : int.Parse(tokens[4]); if (!dragons.ContainsKey(type)) { dragons.Add(type, new List <Dragon>()); } dragons[type].Add(new Dragon(type, name, damage, health, armor)); if (dragons.ContainsKey(type) && dragons[type].Find(x => x.Name == name).Name == name) { List <Dragon> dragonSame = dragons[type].FindAll(x => x.Name == name).ToList(); if (dragonSame.Count > 1) { dragons[type].Remove(dragonSame[1]); Dragon dragon = dragonSame[0]; int index = dragons[type].IndexOf(dragon); dragon.Damage = damage; dragon.Health = health; dragon.Armor = armor; dragons[type][index] = dragon; } } } foreach (var item in dragons) { double averageDamage = item.Value.Average(x => x.Damage); double averageHealth = item.Value.Average(x => x.Health); double averageArmor = item.Value.Average(x => x.Armor); Console.WriteLine($"{item.Key}::({averageDamage:f2}/{averageHealth:f2}/{averageArmor:f2})"); foreach (var dragon in item.Value.OrderBy(x => x.Name)) { Console.WriteLine($"-{dragon.Name} -> damage: {dragon.Damage}, health: {dragon.Health}, armor: {dragon.Armor}"); } } }
static Dictionary <string, List <Dragon> > AddDragon(Dictionary <string, List <Dragon> > dragons, string type, Dragon dragon) { Dictionary <string, List <Dragon> > result = new Dictionary <string, List <Dragon> >(); if (dragons.ContainsKey(type)) { if (dragons[type].Any(s => s.Name.Contains(dragon.Name))) { int index = 0; index = dragons[type].FindIndex(s => s.Name.Contains(dragon.Name)); dragons[type].RemoveAt(index); dragons[type].Add(dragon); } else { dragons[type].Add(dragon); } } else { dragons.Add(type, new List <Dragon>()); dragons[type].Add(dragon); } result = dragons; return(result); }