Advertisement
Guest User

Dragon Army

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