Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- public class Dragon
- {
- public string Colour { get; }
- public int Armor { get; }
- public int Damage { get; }
- public int Health { get; }
- public string Name { get; }
- public Dragon(string colour, string name, int damage, int health, int armor)
- {
- this.Colour = colour;
- this.Name = name;
- this.Damage = damage;
- this.Health = health;
- this.Armor = armor;
- }
- public override string ToString()
- {
- string result = $"-{this.Name} -> damage: {this.Damage}, health: {this.Health}, armor: {this.Armor}";
- return result;
- }
- }
- public class StartUp
- {
- public const int DefaultHealth = 250;
- public const int DefaultDamage = 45;
- public const int DefaultArmor = 10;
- static void Main()
- {
- Dictionary<string, List<Dragon>> allDragons = new Dictionary<string, List<Dragon>>();
- int numberOfDragons = int.Parse(Console.ReadLine());
- for (int i = 0; i < numberOfDragons; i++)
- {
- string[] input = Console.ReadLine()?.Split().ToArray();
- string colour = input[0];
- string name = input[1];
- int damage = int.TryParse(input[2], out int inputDamage) ? inputDamage : DefaultDamage;
- int health = int.TryParse(input[3], out int inputHealth) ? inputHealth : DefaultHealth;
- int armor = int.TryParse(input[4], out int inputArmor) ? inputArmor : DefaultArmor;
- Dragon dragon = new Dragon(colour, name, damage, health, armor);
- if (!allDragons.ContainsKey(colour))
- {
- allDragons.Add(colour, new List<Dragon>());
- }
- Dragon itExists = allDragons[colour].FirstOrDefault(d => d.Name == name && d.Colour == colour);
- if (itExists != null)
- {
- int index = allDragons[colour].IndexOf(itExists);
- allDragons[colour][index] = dragon;
- }
- else
- {
- allDragons[colour].Add(dragon);
- }
- }
- foreach (var dragons in allDragons)
- {
- double totalDamage = dragons.Value.Average(x => x.Damage);
- double totalHealth = dragons.Value.Average(x => x.Health);
- double totalArmor = dragons.Value.Average(x => x.Armor);
- string colourOfDragon = $"{dragons.Key}::({totalDamage:f2}/{totalHealth:f2}/{totalArmor:f2})";
- Console.WriteLine(colourOfDragon);
- List<Dragon> colouredDragons = dragons.Value.OrderBy(x => x.Name).ToList();
- foreach (Dragon dragon in colouredDragons)
- {
- Console.WriteLine(dragon.ToString());
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment