Advertisement
viraco4a

Untitled

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