ghostd0g

Untitled

Feb 18th, 2018
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Exercise11
  6. {
  7.     class Program
  8.     {
  9.  
  10.         static void Main()
  11.         {
  12.  
  13.             var dragons = new Dictionary<string, Dictionary<string, int[]>>();
  14.  
  15.             int n = int.Parse(Console.ReadLine());
  16.  
  17.             for (int i = 0; i < n; i++)
  18.             {
  19.                 var currentDrag = new Dictionary<string, int[]>();
  20.                 string[] input = Console.ReadLine().Split(' ').ToArray();
  21.                 string type = input[0];
  22.                 string name = input[1];
  23.                 int damage = 45;
  24.                 int health = 250;
  25.                 int armor = 10;
  26.  
  27.                 if (input[2] != "null")
  28.                 {
  29.                     damage = int.Parse(input[2]);
  30.                 }              
  31.                 if (input[3] != "null")
  32.                 {
  33.                     health = int.Parse(input[3]);
  34.                 }
  35.                 if (input[4] != "null")
  36.                 {
  37.                     armor = int.Parse(input[4]);
  38.                 }
  39.  
  40.                 if (!dragons.ContainsKey(type))
  41.                 {
  42.                     currentDrag.Add(name,new int[] { damage, health, armor });
  43.                     dragons.Add(type, currentDrag);
  44.                 }
  45.                 else
  46.                 {
  47.                     if (!dragons[type].ContainsKey(name))
  48.                     {
  49.                         dragons[type].Add(name, new int[] { damage, health, armor });
  50.                     }
  51.                     else
  52.                     {                      
  53.                         dragons[type][name] = new int[]{damage, health, armor};
  54.                     }
  55.                 }
  56.             }
  57.  
  58.             foreach (var type in dragons)
  59.             {
  60.                 Console.WriteLine($"{type.Key}::({(type.Value.Select(x => x.Value[0]).Average()):F2}/{(type.Value.Select(x => x.Value[1]).Average()):F2}/{(type.Value.Select(x => x.Value[2]).Average()):F2})");
  61.  
  62.                 foreach (var name in type.Value.OrderBy(x => x.Key))
  63.                 {
  64.                     Console.WriteLine($"-{name.Key} -> damage: {name.Value[0]}, health: {name.Value[1]}, armor: {name.Value[2]}");
  65.                 }
  66.  
  67.             }
  68.  
  69.         }
  70.  
  71.     }
  72.  
  73. }
Add Comment
Please, Sign In to add comment