Advertisement
bullit3189

Dragon Army-Dictionaries with Class

Feb 12th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5.  
  6. public class Program
  7. {
  8. public class Dragon
  9. {
  10. public string Color {get; set;}
  11. public string Name {get; set;}
  12. public int Damage {get; set;}
  13. public int Health {get; set;}
  14. public int Armor {get; set;}
  15. }
  16. public static void Main()
  17. {
  18. List<Dragon> dragons = new List<Dragon>();
  19. List<string> colors = new List<string>();
  20.  
  21. int n = int.Parse(Console.ReadLine());
  22.  
  23. for (int i=0; i<n; i++)
  24. {
  25. string[] tokens = Console.ReadLine().Split();
  26. string color = tokens[0];
  27. string name = tokens[1];
  28. string damage = tokens[2];
  29. int dmg =0;
  30. if (damage == "null")
  31. {
  32. dmg =45;
  33. }
  34. else
  35. {
  36. dmg = int.Parse(damage);
  37. }
  38. string health = tokens[3];
  39. int hp =0;
  40. if (health == "null")
  41. {
  42. hp = 250;
  43. }
  44. else
  45. {
  46. hp = int.Parse(health);
  47. }
  48. string defense = tokens[4];
  49. int armor =0;
  50. if (defense == "null")
  51. {
  52. armor = 10;
  53. }
  54. else
  55. {
  56. armor = int.Parse(defense);
  57. }
  58.  
  59. Dragon dragon = dragons.FirstOrDefault(d=>d.Color==color && d.Name == name);
  60.  
  61. if (dragon == null)
  62. {
  63. dragons.Add(new Dragon
  64. {
  65. Color = color,
  66. Name = name,
  67. Damage = dmg,
  68. Health = hp,
  69. Armor = armor
  70. });
  71.  
  72. colors.Add(color);
  73. }
  74. else
  75. {
  76. dragon.Damage = dmg;
  77. dragon.Health = hp;
  78. dragon.Armor = armor;
  79. }
  80. }
  81.  
  82. colors = colors.Distinct().ToList();
  83.  
  84. foreach (var currColor in colors)
  85. {
  86. var dragonsStats = dragons.Where(x=>x.Color == currColor).OrderBy(x=>x.Name);
  87. var avrDmg = dragonsStats.Average(x=>x.Damage);
  88. var avrHp = dragonsStats.Average(x=>x.Health);
  89. var avrArmor = dragonsStats.Average(x=>x.Armor);
  90. Console.WriteLine("{0}::({1:f2}/{2:f2}/{3:f2})",currColor,avrDmg,avrHp,avrArmor);
  91.  
  92. foreach (var currDragon in dragonsStats)
  93. {
  94. Console.WriteLine("-{0} -> damage: {1}, health: {2}, armor: {3}",currDragon.Name,currDragon.Damage,currDragon.Health,currDragon.Armor);
  95. }
  96. }
  97. }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement