Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Dragons
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- public class Program
- {
- private static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- Dictionary<string, List<Dragon>> theDick = new Dictionary<string, List<Dragon>>();
- for (int i = 0; i < n; i++)
- {
- string[] input = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- string type = input[0];
- string name = input[1];
- int damage;
- int health;
- int armor;
- bool damageParser = int.TryParse(input[2], out damage);
- bool healthParser = int.TryParse(input[3], out health);
- bool armorParser = int.TryParse(input[4], out armor);
- Dragon dragon = new Dragon(type, name);
- if (damageParser)
- {
- dragon.Damage = damage;
- }
- if (healthParser)
- {
- dragon.Health = health;
- }
- if (armorParser)
- {
- dragon.Armor = armor;
- }
- if (!theDick.ContainsKey(type))
- {
- theDick[type] = new List<Dragon>();
- theDick[type].Add(dragon);
- }
- else
- {
- int index = -1;
- foreach (var kvp in theDick)
- {
- foreach (var dr in kvp.Value)
- {
- if (dragon.CompareTo(dr) == 0)
- {
- index = kvp.Value.IndexOf(dr);
- }
- }
- }
- if (index == -1)
- {
- theDick[type].Add(dragon);
- }
- else
- {
- theDick[type][index] = dragon;
- }
- }
- }
- foreach (var kvp in theDick)
- {
- Console.WriteLine($"{kvp.Key}::({kvp.Value.Average(d => d.Damage):F2}/{kvp.Value.Average(d => d.Health):F2}/{kvp.Value.Average(d => d.Armor):F2})");
- foreach (var dragon in kvp.Value.OrderBy(d => d.Name))
- {
- Console.WriteLine($"-{dragon.Name} -> damage: {dragon.Damage}, health: {dragon.Health}, armor: {dragon.Armor}");
- }
- }
- }
- }
- public class Dragon : IComparable<Dragon>
- {
- public Dragon(string type, string name)
- {
- this.Type = type;
- this.Name = name;
- this.Health = 250;
- this.Damage = 45;
- this.Armor = 10;
- }
- public string Type { get; set; }
- public string Name { get; set; }
- public int Health { get; set; }
- public int Damage { get; set; }
- public int Armor { get; set; }
- public int CompareTo(Dragon other)
- {
- if (this.Type.Equals(other.Type) && this.Name.Equals(other.Name))
- {
- return 0;
- }
- return -1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement