Guest User

11. Dragon Army

a guest
Feb 19th, 2018
835
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.89 KB | None | 0 0
  1. namespace _11._Dragon_Army
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.  
  7.     public class DragonArmy
  8.     {
  9.         public static void Main()
  10.         {
  11.             var data = new Dictionary<string, SortedDictionary<string, int[]>>();
  12.  
  13.             var n = int.Parse(Console.ReadLine());
  14.  
  15.             for (var i = 0; i < n; i++)
  16.             {
  17.                 var tokens = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  18.  
  19.                 var type = tokens[0];
  20.                 var name = tokens[1];
  21.                 var damage = 0;
  22.                 var health = 0;
  23.                 var armor = 0;
  24.  
  25.                 damage = tokens[2] == "null" ? 45 : int.Parse(tokens[2]);
  26.                 health = tokens[3] == "null" ? 250 : int.Parse(tokens[3]);
  27.                 armor = tokens[4] == "null" ? 10 : int.Parse(tokens[4]);
  28.  
  29.                 if (!data.ContainsKey(type))
  30.                 {
  31.                     data.Add(type, new SortedDictionary<string, int[]>());
  32.                 }
  33.  
  34.                 if (!data[type].ContainsKey(name))
  35.                 {
  36.                     data[type][name] = new int[3];
  37.                 }
  38.  
  39.                 data[type][name][0] = damage;
  40.                 data[type][name][1] = health;
  41.                 data[type][name][2] = armor;
  42.             }
  43.  
  44.             foreach (var outerKvp in data)
  45.             {
  46.                 Console.WriteLine($"{outerKvp.Key}::({outerKvp.Value.Select(x => x.Value[0]).Average():F}/{outerKvp.Value.Select(x => x.Value[1]).Average():f}/{outerKvp.Value.Select(x => x.Value[2]).Average():f})");
  47.  
  48.                 foreach (var innerKvp in outerKvp.Value)
  49.                 {
  50.                     Console.WriteLine($"-{innerKvp.Key} -> damage: {innerKvp.Value[0]}, health: { innerKvp.Value[1]}, armor: {innerKvp.Value[2]}");
  51.                 }
  52.             }
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment