static void Main(string[] args)
        {
            Dictionary <string, SortedDictionary <string, DragonStats> > dragonsRoster = new Dictionary <string, SortedDictionary <string, DragonStats> >();
            int numDragons = int.Parse(Console.ReadLine());

            for (int i = 0; i < numDragons; i++)
            {
                string[] input      = Console.ReadLine().Trim().Split();
                string   dragonType = input[0];
                string   dragonName = input[1];
                string   damage     = input[2];
                string   health     = input[3];
                string   armor      = input[4];

                if (!dragonsRoster.ContainsKey(dragonType))
                {
                    dragonsRoster[dragonType] = new SortedDictionary <string, DragonStats>();
                }

                dragonsRoster[dragonType][dragonName] = new DragonStats(damage, health, armor);
            }

            foreach (KeyValuePair <string, SortedDictionary <string, DragonStats> > dragonType in dragonsRoster)
            {
                Console.WriteLine("{0}::({1:0.00}/{2:0.00}/{3:0.00})",
                                  dragonType.Key, dragonType.Value.Average(dragon => (float)dragon.Value.damage), dragonType.Value.Average(dragon => (float)dragon.Value.health), dragonType.Value.Average(dragon => (float)dragon.Value.armor));

                foreach (KeyValuePair <string, DragonStats> dragon in dragonType.Value)
                {
                    Console.WriteLine($"-{dragon.Key} -> damage: {dragon.Value.damage}, health: {dragon.Value.health}, armor: {dragon.Value.armor}");
                }
            }
        }
示例#2
0
        public static void Main()
        {
            var dragonColors = new Dictionary <string, SortedDictionary <string, DragonStats> >();
            int n            = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                var    split = Console.ReadLine().Split();
                string color = split[0];
                string name  = split[1];
                if (!int.TryParse(split[2], out int damage))
                {
                    damage = 45;
                }
                if (!int.TryParse(split[3], out int health))
                {
                    health = 250;
                }
                if (!int.TryParse(split[4], out int armor))
                {
                    armor = 10;
                }

                if (!dragonColors.ContainsKey(color))
                {
                    dragonColors[color] = new SortedDictionary <string, DragonStats>();
                }
                dragonColors[color][name] = new DragonStats(damage, health, armor);
            }
            foreach (var color in dragonColors)
            {
                double averageDamage = color.Value
                                       .Values
                                       .Select(stats => stats.Damage)
                                       .Average();
                double averageHealth = color.Value
                                       .Values
                                       .Select(stats => stats.Health)
                                       .Average();
                double averageArmor = color.Value
                                      .Values
                                      .Select(stats => stats.Armor)
                                      .Average();
                Console.WriteLine($"{color.Key}::({averageDamage:f2}/{averageHealth:f2}/{averageArmor:f2})");
                foreach (var dragon in color.Value)
                {
                    int damage = dragon.Value.Damage;
                    int health = dragon.Value.Health;
                    int armor  = dragon.Value.Armor;
                    Console.WriteLine($"-{dragon.Key} -> damage: {damage}, health: {health}, armor: {armor}");
                }
            }
        }