Advertisement
Guest User

Untitled

a guest
Jan 3rd, 2018
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. namespace Dragons
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6.  
  7. public class Program
  8. {
  9. private static void Main()
  10. {
  11. int n = int.Parse(Console.ReadLine());
  12. Dictionary<string, List<Dragon>> theDick = new Dictionary<string, List<Dragon>>();
  13. for (int i = 0; i < n; i++)
  14. {
  15. string[] input = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  16. string type = input[0];
  17. string name = input[1];
  18. int damage;
  19. int health;
  20. int armor;
  21. bool damageParser = int.TryParse(input[2], out damage);
  22. bool healthParser = int.TryParse(input[3], out health);
  23. bool armorParser = int.TryParse(input[4], out armor);
  24.  
  25. Dragon dragon = new Dragon(type, name);
  26. if (damageParser)
  27. {
  28. dragon.Damage = damage;
  29. }
  30. if (healthParser)
  31. {
  32. dragon.Health = health;
  33. }
  34. if (armorParser)
  35. {
  36. dragon.Armor = armor;
  37. }
  38.  
  39. if (!theDick.ContainsKey(type))
  40. {
  41. theDick[type] = new List<Dragon>();
  42. theDick[type].Add(dragon);
  43. }
  44. else
  45. {
  46. int index = -1;
  47. foreach (var kvp in theDick)
  48. {
  49. foreach (var dr in kvp.Value)
  50. {
  51. if (dragon.CompareTo(dr) == 0)
  52. {
  53. index = kvp.Value.IndexOf(dr);
  54. }
  55. }
  56. }
  57. if (index == -1)
  58. {
  59. theDick[type].Add(dragon);
  60. }
  61. else
  62. {
  63. theDick[type][index] = dragon;
  64. }
  65. }
  66. }
  67. foreach (var kvp in theDick)
  68. {
  69. Console.WriteLine($"{kvp.Key}::({kvp.Value.Average(d => d.Damage):F2}/{kvp.Value.Average(d => d.Health):F2}/{kvp.Value.Average(d => d.Armor):F2})");
  70. foreach (var dragon in kvp.Value.OrderBy(d => d.Name))
  71. {
  72. Console.WriteLine($"-{dragon.Name} -> damage: {dragon.Damage}, health: {dragon.Health}, armor: {dragon.Armor}");
  73. }
  74. }
  75. }
  76. }
  77.  
  78. public class Dragon : IComparable<Dragon>
  79. {
  80. public Dragon(string type, string name)
  81. {
  82. this.Type = type;
  83. this.Name = name;
  84. this.Health = 250;
  85. this.Damage = 45;
  86. this.Armor = 10;
  87. }
  88.  
  89. public string Type { get; set; }
  90.  
  91. public string Name { get; set; }
  92.  
  93. public int Health { get; set; }
  94.  
  95. public int Damage { get; set; }
  96.  
  97. public int Armor { get; set; }
  98.  
  99. public int CompareTo(Dragon other)
  100. {
  101. if (this.Type.Equals(other.Type) && this.Name.Equals(other.Name))
  102. {
  103. return 0;
  104. }
  105. return -1;
  106. }
  107. }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement