Advertisement
viraco4a

DragonArmyNoClasses

Feb 26th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 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 _11_DragonArmy
  8. {
  9. class Program
  10. {
  11. static void Main()
  12. {
  13. var AllData = new Dictionary<string, SortedDictionary<string, Dictionary<string, int>>>();
  14. var avrData = new Dictionary<string, double[]>();
  15. int n = int.Parse(Console.ReadLine());
  16. for (int i = 0; i < n; i++)
  17. {
  18. string[] inputLine = GetInput();
  19. string type = inputLine[0];
  20. string dragon = inputLine[1];
  21. int damage = GetStat(inputLine, 45, 2);
  22. int health = GetStat(inputLine, 250, 3);
  23. int armor = GetStat(inputLine, 10, 4);
  24. if (!AllData.ContainsKey(type))
  25. {
  26. AllData[type] = new SortedDictionary<string, Dictionary<string, int>>();
  27. avrData[type] = new double[] { 0.0, 0.0, 0.0 };
  28. }
  29. if (!AllData[type].ContainsKey(dragon))
  30. {
  31. AllData[type][dragon] = new Dictionary<string, int>()
  32. {
  33. { "damage", damage }, { "health", health }, { "armor", armor }
  34. };
  35. }
  36. else
  37. {
  38. AllData[type][dragon]["damage"] = damage;
  39. AllData[type][dragon]["health"] = health;
  40. AllData[type][dragon]["armor"] = armor;
  41. }
  42. }
  43. foreach (var type in AllData)
  44. {
  45. double totalDamage = 0.0;
  46. double totalHealth = 0.0;
  47. double totalArmor = 0.0;
  48. foreach (var dragon in type.Value)
  49. {
  50. totalDamage += dragon.Value["damage"];
  51. totalHealth += dragon.Value["health"];
  52. totalArmor += dragon.Value["armor"];
  53. }
  54. avrData[type.Key][0] = totalDamage / type.Value.Count;
  55. avrData[type.Key][1] = totalHealth / type.Value.Count;
  56. avrData[type.Key][2] = totalArmor / type.Value.Count;
  57. }
  58. foreach (var type in AllData)
  59. {
  60. Console.WriteLine($"{type.Key}::({avrData[type.Key][0]:f2}/{avrData[type.Key][1]:f2}/{avrData[type.Key][2]:f2})");
  61. foreach (var dragon in type.Value)
  62. {
  63. Console.WriteLine($"-{dragon.Key} -> damage: {dragon.Value["damage"]}, health: {dragon.Value["health"]}, armor: {dragon.Value["armor"]}");
  64. }
  65. }
  66. }
  67.  
  68. private static int GetStat(string[] inputLine, int defaultValue, int index)
  69. {
  70. int stat = 0;
  71. try
  72. {
  73. stat = int.Parse(inputLine[index]);
  74. }
  75. catch (Exception)
  76. {
  77. stat = defaultValue;
  78. }
  79.  
  80. return stat;
  81. }
  82.  
  83. private static string[] GetInput()
  84. {
  85. return Console.ReadLine()
  86. .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  87. .ToArray();
  88. }
  89. }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement