Advertisement
viraco4a

Untitled

Jan 2nd, 2018
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.59 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 task_12
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int n = int.Parse(Console.ReadLine());
  14. List<DragonType> ListOfDragonTypes = new List<DragonType>();
  15. List<DragonType> UpgradedList = new List<DragonType>();
  16. for (int i = 0; i < n; i++)
  17. {
  18. Dragon newDragon = ReadInput();
  19. bool newDragonType = true;
  20.  
  21. for (int j = 0; j < ListOfDragonTypes.Count; j++)
  22. {
  23. if (ListOfDragonTypes.ElementAt(j).typeName == newDragon.Type)
  24. {
  25. UpgradedList = UpgradingListOfDragonType(ListOfDragonTypes, ListOfDragonTypes.ElementAt(j), newDragon);
  26. ListOfDragonTypes = UpgradedList;
  27. newDragonType = false;
  28. }
  29. }
  30.  
  31. if (newDragonType)
  32. {
  33. ListOfDragonTypes = AddNewDragonType(ListOfDragonTypes, newDragon);
  34. }
  35. }
  36. PrintTheResult(ListOfDragonTypes);
  37. }
  38.  
  39. static void PrintTheResult(List<DragonType> finalList)
  40. {
  41. foreach (DragonType item in finalList)
  42. {
  43. string type = item.typeName;
  44. double avrDamage = item.SetAvrDamage(item.ListOfDragons);
  45. double avrHealth = item.SetAvrHealth(item.ListOfDragons);
  46. double avrArmor = item.SetAvrArmor(item.ListOfDragons);
  47. Console.WriteLine("{0}::({1:f2}/{2:f2}/{3:f2})", type, avrDamage, avrHealth, avrArmor);
  48. List<Dragon> currentDragons = item.ListOfDragons;
  49. currentDragons = SortAlpha(currentDragons);
  50. foreach (Dragon dragon in currentDragons)
  51. {
  52. string dragonName = dragon.Name;
  53. long dragonDamage = dragon.GetDamage();
  54. long dragonHealth = dragon.GetHealth();
  55. long dragonArmor = dragon.GetArmor();
  56. Console.WriteLine("-{0} -> damage: {1}, health: {2}, armor: {3}", dragonName, dragonDamage, dragonHealth, dragonArmor);
  57. }
  58. }
  59. }
  60.  
  61. static List<Dragon> SortAlpha(List<Dragon> listToSort)
  62. {
  63. List<Dragon> sortedList = new List<Dragon>();
  64. sortedList = listToSort.OrderBy(o => o.Name).ToList();
  65. return sortedList;
  66. }
  67.  
  68. static List<DragonType> UpgradingListOfDragonType(List<DragonType> ListToBeUpgraded, DragonType TypeToBeUpgraded, Dragon newDragon)
  69. {
  70. for (int i = 0; i < ListToBeUpgraded.Count; i++)
  71. {
  72. if (ListToBeUpgraded.ElementAt(i) == TypeToBeUpgraded)
  73. {
  74. ListToBeUpgraded.ElementAt(i).ListOfDragons.Add(newDragon);
  75. }
  76. }
  77. return ListToBeUpgraded;
  78. }
  79.  
  80. static List<DragonType> AddNewDragonType(List<DragonType> listOfDragonTypes, Dragon addedNewDragon)
  81. {
  82. DragonType newType = new DragonType(addedNewDragon.Type);
  83. newType.ListOfDragons.Add(addedNewDragon);
  84. listOfDragonTypes.Add(newType);
  85. return listOfDragonTypes;
  86. }
  87.  
  88. static Dragon ReadInput()
  89. {
  90. string[] input = Console.ReadLine().Split(' ').ToArray();
  91. if (input[2] == "null")
  92. {
  93. input[2] = "45";
  94. }
  95. if (input[3] == "null")
  96. {
  97. input[3] = "250";
  98. }
  99. if (input[4] == "null")
  100. {
  101. input[4] = "10";
  102. }
  103. Dragon NewDragon = new Dragon();
  104. NewDragon.Name = input[1];
  105. NewDragon.Type = input[0];
  106. NewDragon.SetDamage(long.Parse(input[2]));
  107. NewDragon.SetHealth(long.Parse(input[3]));
  108. NewDragon.SetArmor(long.Parse(input[4]));
  109. return NewDragon;
  110. }
  111. }
  112. class Dragon
  113. {
  114. public string Type { get; set; }
  115. public string Name { get; set; }
  116. private long damage = 45;
  117. private long health = 250;
  118. private long armor = 10;
  119.  
  120. public long GetDamage()
  121. {
  122. return damage;
  123. }
  124.  
  125. public long GetHealth()
  126. {
  127. return health;
  128. }
  129.  
  130. public long GetArmor()
  131. {
  132. return armor;
  133. }
  134.  
  135. public long SetDamage(long Damage)
  136. {
  137. this.damage = Damage;
  138. return Damage;
  139. }
  140.  
  141. public long SetHealth(long Health)
  142. {
  143. this.health = Health;
  144. return Health;
  145. }
  146.  
  147. public long SetArmor(long Armor)
  148. {
  149. this.armor = Armor;
  150. return Armor;
  151. }
  152. }
  153.  
  154. class DragonType
  155. {
  156. public DragonType(string TypeName)
  157. {
  158. this.typeName = TypeName;
  159. }
  160. public List<Dragon> ListOfDragons = new List<Dragon>();
  161. public string typeName;
  162. private double avrDamage;
  163. private double avrHealth;
  164. private double avrArmor;
  165.  
  166. public double GetAvrDamage()
  167. {
  168. return avrArmor;
  169. }
  170.  
  171. public double GetAvrHealth()
  172. {
  173. return avrHealth;
  174. }
  175.  
  176. public double GetAvrArmor()
  177. {
  178. return avrArmor;
  179. }
  180.  
  181. public double SetAvrDamage(List<Dragon> listOfDragons)
  182. {
  183. double sum = 0;
  184. foreach (Dragon item in listOfDragons)
  185. {
  186. sum += item.GetDamage();
  187. }
  188. this.avrDamage = sum / listOfDragons.Count;
  189. return avrDamage;
  190. }
  191.  
  192. public double SetAvrHealth(List<Dragon> listOfDragons)
  193. {
  194. double sum = 0;
  195. foreach (Dragon item in listOfDragons)
  196. {
  197. sum += item.GetHealth();
  198. }
  199. this.avrHealth = sum / listOfDragons.Count;
  200. return avrHealth;
  201. }
  202.  
  203. public double SetAvrArmor(List<Dragon> listOfDragons)
  204. {
  205. double sum = 0;
  206. foreach (Dragon item in listOfDragons)
  207. {
  208. sum += item.GetArmor();
  209. }
  210. this.avrArmor = sum / listOfDragons.Count;
  211. return avrArmor;
  212. }
  213.  
  214. }
  215. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement