Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _11Problem_DragonArmy
- {
- class Program
- {
- static void Main(string[] args)
- {
- // Read the input
- int numberOfDragons = int.Parse(Console.ReadLine());
- // Keep: Key = Dragon Type , Value = (Key = Dragon Name) + (Value = List with damage, health and armor).
- var dragonsTypeAndName = new Dictionary<string, SortedDictionary<string, List<double>>>();
- for (int i = 1; i <= numberOfDragons; i++)
- {
- string[] inputDragonInfo = Console.ReadLine().Split();
- string type = inputDragonInfo[0];
- string name = inputDragonInfo[1];
- uint damage;
- uint health;
- uint armor;
- bool tryDamage = uint.TryParse(inputDragonInfo[2], out damage);
- bool tryHealth = uint.TryParse(inputDragonInfo[3], out health);
- bool tryArmor = uint.TryParse(inputDragonInfo[4], out armor);
- if (tryDamage == false)
- {
- damage = 45;
- }
- if (tryHealth == false)
- {
- health = 250;
- }
- if (tryArmor == false)
- {
- armor = 10;
- }
- if (dragonsTypeAndName.ContainsKey(type) == false)
- {
- // Fill the dictionary with new type of dragon, which have a name and list of damage, health and armor.
- dragonsTypeAndName.Add(type, new SortedDictionary<string, List<double>>());
- dragonsTypeAndName[type].Add(name, new List<double>());
- dragonsTypeAndName[type][name].Add(damage);
- dragonsTypeAndName[type][name].Add(health);
- dragonsTypeAndName[type][name].Add(armor);
- }
- else
- {
- // Fill the dictionary with the existing type with new name and list of damage, health and armor.
- if (dragonsTypeAndName[type].ContainsKey(name) == false)
- {
- dragonsTypeAndName[type].Add(name, new List<double>());
- dragonsTypeAndName[type][name].Add(damage);
- dragonsTypeAndName[type][name].Add(health);
- dragonsTypeAndName[type][name].Add(armor);
- }
- else
- {
- // Overwrite the dragons stats (damage, health and armor) on already existing type and name of dragon.
- dragonsTypeAndName[type][name][0] = damage;
- dragonsTypeAndName[type][name][1] = health;
- dragonsTypeAndName[type][name][2] = armor;
- }
- }
- }
- foreach (var typeName in dragonsTypeAndName)
- {
- double avgDmg = typeName.Value.Select(x => x.Value[0]).Average();
- double avgHeal = typeName.Value.Select(x => x.Value[1]).Average();
- double avgArm = typeName.Value.Select(x => x.Value[2]).Average();
- Console.WriteLine($"{typeName.Key}::({avgDmg:f2}/{avgHeal:f2}/{avgArm:f2})");
- foreach (var nameStats in typeName.Value)
- {
- Console.WriteLine($"-{nameStats.Key} -> damage: {nameStats.Value[0]}, health: {nameStats.Value[1]}, armor: {nameStats.Value[2]}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement