Advertisement
viraco4a

DragonArmyNoClasses

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