Advertisement
Guest User

s

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