ZhivkoPetkov

DragonArmy

Jun 18th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.60 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace dragonArmy
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int dragonsCount = int.Parse(Console.ReadLine());
  14.  
  15.            
  16.             var dragons = new Dictionary<string, SortedDictionary<string, int[]>>();
  17.  
  18.             for (int i = 0; i < dragonsCount; i++)
  19.             {
  20.                 var input = Console.ReadLine().Split(new char[] { ' ' },StringSplitOptions.RemoveEmptyEntries).ToList();
  21.  
  22.                 string type = input[0];
  23.                 string name = input[1];
  24.                 int health = 250;
  25.                 int damage = 45;
  26.                 int armor = 10;
  27.  
  28.                 if (input[2] != "null")
  29.                 {
  30.                     damage = int.Parse(input[2]);
  31.                 }
  32.                 if (input[3] != "null")
  33.                 {
  34.                     health = int.Parse(input[3]);
  35.                 }
  36.                 if (input[4] != "null")
  37.                 {
  38.                     armor = int.Parse(input[4]);
  39.                 }
  40.  
  41.                 if (dragons.ContainsKey(type)==false)
  42.                 {
  43.                     dragons.Add(type, new SortedDictionary<string, int[]>());
  44.                 }
  45.  
  46.  
  47.                
  48.                 if (dragons[type].ContainsKey(name))
  49.                 {
  50.                     dragons[type][name][0] =damage;
  51.                     dragons[type][name][1] =health;
  52.                     dragons[type][name][2] =armor;
  53.                 }
  54.                 else
  55.                 {
  56.                     dragons[type].Add(name, new int[] { damage, health, armor });
  57.                 }
  58.  
  59.  
  60.             }
  61.  
  62.             foreach (var drag in dragons)
  63.             {
  64.                 var avgrD = drag.Value.Select(x => x.Value[0]).Average();
  65.                 double avgrH = drag.Value.Select(x => x.Value[1]).Average();
  66.                 double avgrA = drag.Value.Select(x => x.Value[2]).Average();
  67.  
  68.                 Console.WriteLine($"{drag.Key}::({avgrD:F}/{avgrH:f}/{avgrA:f})");
  69.  
  70.                 foreach (var item in drag.Value)
  71.                 {
  72.                     Console.WriteLine($"-{item.Key} -> damage: {item.Value[0]}, health: {item.Value[1]}, armor: {item.Value[2]}");
  73.                 }
  74.             }
  75.  
  76.  
  77.         }
  78.     }
  79.  
  80.     class Dragon
  81.     {
  82.         public string Name { get; set; }
  83.         public string Type { get; set; }
  84.         public double Damage { get; set; }
  85.         public double Health { get; set; }
  86.         public double Armor { get; set; }
  87.  
  88.     }
  89.  
  90.    
  91. }
Advertisement
Add Comment
Please, Sign In to add comment