WindFell

Dragon Army

Apr 23rd, 2018
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class DragonArmy
  6. {
  7.     static void Main(string[] args)
  8.     {
  9.         int count = int.Parse(Console.ReadLine());
  10.  
  11.         var dragons = new Dictionary<string, Dictionary<string, Dragon>>();
  12.  
  13.         for (int currentDragon = 0; currentDragon < count; currentDragon++)
  14.         {
  15.             string[] input = Console.ReadLine()
  16.                 .Split()
  17.                 .ToArray();
  18.  
  19.             string type = input[0];
  20.             string name = input[1];
  21.             int damage = 45;
  22.             int health = 250;
  23.             int armor = 10;
  24.  
  25.             try
  26.             {
  27.                 damage = int.Parse(input[2]);
  28.             }
  29.             catch (Exception) { }
  30.  
  31.             try
  32.             {
  33.                 health = int.Parse(input[3]);
  34.             }
  35.             catch (Exception) { }
  36.  
  37.             try
  38.             {
  39.                 armor = int.Parse(input[4]);
  40.             }
  41.             catch (Exception) { }
  42.  
  43.             if (dragons.ContainsKey(type) == false)
  44.             {
  45.                 dragons.Add(type, new Dictionary<string, Dragon>());
  46.             }
  47.  
  48.             if (dragons[type].ContainsKey(name) == false)
  49.             {
  50.                 dragons[type].Add(name, new Dragon());
  51.             }
  52.  
  53.             dragons[type][name].damage = damage;
  54.             dragons[type][name].health = health;
  55.             dragons[type][name].armor = armor;
  56.         }
  57.  
  58.         foreach (var type in dragons)
  59.         {
  60.             double averageDamage = 1.0 * type.Value.Values.Sum(x => x.damage) / type.Value.Count;
  61.             double averageHealth = 1.0 * type.Value.Values.Sum(x => x.health) / type.Value.Count;
  62.             double averageArmor = 1.0 * type.Value.Values.Sum(x => x.armor) / type.Value.Count;
  63.  
  64.             Console.WriteLine($"{type.Key}::({averageDamage:F2}/{averageHealth:F2}/{averageArmor:F2})");
  65.  
  66.             foreach (var name in type.Value.OrderBy(x => x.Key))
  67.             {
  68.                 Console.WriteLine($"-{name.Key} -> damage: {name.Value.damage}, health: {name.Value.health}, armor: {name.Value.armor}");
  69.             }
  70.         }
  71.     }
  72. }
  73.  
  74. class Dragon
  75. {
  76.     public int damage { get; set; }
  77.     public int health { get; set; }
  78.     public int armor { get; set; }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment