Advertisement
Guest User

Untitled

a guest
May 28th, 2016
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4.  
  5. namespace DragonArmy
  6. {
  7. public class DragonArmy
  8. {
  9. public static void Main()
  10. {
  11. var data = new Dictionary<string, SortedDictionary<string, int[]>>();
  12. var regex = new Regex(@"([a-zA-Z]*)\s*([a-zA-Z]*)\s*(null|\d+)\s*(null|\d+)\s*(null|\d+)");
  13.  
  14. var n = int.Parse(Console.ReadLine());
  15.  
  16. for (var i = 0; i < n; i++)
  17. {
  18. var input = Console.ReadLine();
  19. var match = regex.Match(input);
  20.  
  21. if (match.Success)
  22. {
  23. var type = match.Groups[1].Value;
  24. var name = match.Groups[2].Value;
  25. var damage = 0;
  26. var health = 0;
  27. var armor = 0;
  28. damage = match.Groups[3].Value == "null" ? 45 : int.Parse(match.Groups[3].Value);
  29. health = match.Groups[4].Value == "null" ? 250 : int.Parse(match.Groups[4].Value);
  30. armor = match.Groups[5].Value == "null" ? 10 : int.Parse(match.Groups[5].Value);
  31.  
  32. if (!data.ContainsKey(type))
  33. {
  34. data.Add(type, new SortedDictionary<string, int[]>());
  35. }
  36.  
  37. if (!data[type].ContainsKey(name))
  38. {
  39. data[type][name] = new int[3];
  40. }
  41.  
  42. data[type][name][0] = damage;
  43. data[type][name][1] = health;
  44. data[type][name][2] = armor;
  45. }
  46. }
  47.  
  48. foreach (var outerPair in data)
  49. {
  50. var average = CalculateAverage(outerPair.Value);
  51.  
  52. Console.WriteLine("{0}::({1:F}/{2:f}/{3:f})", outerPair.Key, average[0],
  53. average[1], average[2]);
  54.  
  55. foreach (var inner in outerPair.Value)
  56. {
  57. Console.WriteLine("-{0} -> damage: {1}, health: {2}, armor: {3}", inner.Key, inner.Value[0],
  58. inner.Value[1], inner.Value[2]);
  59. }
  60. }
  61. }
  62.  
  63. private static double[] CalculateAverage(SortedDictionary<string, int[]> list)
  64. {
  65. double totalEntries = list.Count;
  66. var totalDamage = 0;
  67. var totalHealth = 0;
  68. var totalArmor = 0;
  69.  
  70. foreach (var element in list)
  71. {
  72. totalDamage += element.Value[0];
  73. totalHealth += element.Value[1];
  74. totalArmor += element.Value[2];
  75. }
  76.  
  77. return new[]
  78. {
  79. totalDamage/totalEntries, totalHealth/totalEntries, totalArmor/totalEntries
  80. };
  81. }
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement