Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _03.Jarvis
  6. {
  7. public class Arms
  8. {
  9. public long EnergyConsumption { get; set; }
  10. public int ReachDistance { get; set; }
  11. public int CountOfFingers { get; set; }
  12.  
  13. public override string ToString()
  14. {
  15. return string.Format(
  16. $"#Arm:{Environment.NewLine}###Energy consumption: {EnergyConsumption}{Environment.NewLine}###Reach: {ReachDistance}{Environment.NewLine}###Fingers: {CountOfFingers}");
  17. }
  18. }
  19.  
  20. public class Legs
  21. {
  22. public long EnergyConsumption { get; set; }
  23. public long Strenght { get; set; }
  24. public long Speed { get; set; }
  25.  
  26. public override string ToString()
  27. {
  28. return string.Format(
  29. $"#Leg:{Environment.NewLine}###Energy consumption: {EnergyConsumption}{Environment.NewLine}###Strength: {Strenght}{Environment.NewLine}###Speed: {Speed}");
  30. }
  31. }
  32.  
  33. public class Torso
  34. {
  35. public long EnergyConsumption { get; set; }
  36. public double ProcessorSizeInSentimeters { get; set; }
  37. public string HousingMaterial { get; set; }
  38.  
  39. public override string ToString()
  40. {
  41. return string.Format(
  42. $"#Torso:{Environment.NewLine}###Energy consumption: {EnergyConsumption}{Environment.NewLine}###Processor size: {ProcessorSizeInSentimeters:f1}{Environment.NewLine}###Corpus material: {HousingMaterial}");
  43. }
  44. }
  45.  
  46. public class Head
  47. {
  48. public long EnergyConsumption { get; set; }
  49. public long Iq { get; set; }
  50. public string SkinMaterial { get; set; }
  51.  
  52. public override string ToString()
  53. {
  54. return string.Format(
  55. $"#Head:{Environment.NewLine}###Energy consumption: {EnergyConsumption}{Environment.NewLine}###IQ: {Iq}{Environment.NewLine}###Skin material: {SkinMaterial}");
  56. }
  57. }
  58.  
  59. public class Jarvis
  60. {
  61. public static void Main()
  62. {
  63. long maxEnergy = long.Parse(Console.ReadLine());
  64. string lines = Console.ReadLine();
  65. var arms = new Dictionary<string, List<Arms>>();
  66. arms["Arm"] = new List<Arms>();
  67.  
  68. var legs = new Dictionary<string, List<Legs>>();
  69. legs["Leg"] = new List<Legs>();
  70.  
  71. var torso = new Dictionary<string, List<Torso>>();
  72. torso["Torso"] = new List<Torso>();
  73.  
  74. var head = new Dictionary<string, List<Head>>();
  75. head["Head"] = new List<Head>();
  76.  
  77. var robot = new Dictionary<string, List<object>>();
  78.  
  79. while (lines != "Assemble!")
  80. {
  81. var components = lines.Split();
  82.  
  83. string typeOfComponent = components[0];
  84. long energyConsumption = long.Parse(components[1]);
  85. string property1 = components[2];
  86. string property2 = components[3];
  87.  
  88. AddComponents(arms, legs, torso, head, typeOfComponent, energyConsumption, property1, property2);
  89.  
  90. robot[typeOfComponent] = new List<object>();
  91.  
  92. lines = Console.ReadLine();
  93. }
  94.  
  95. long energy = 0;
  96. energy = CalculateComponentsEnergy(arms, legs, torso, head, robot, energy);
  97.  
  98. PrintRobot(maxEnergy, robot, energy);
  99.  
  100. }
  101.  
  102. private static void PrintRobot(long maxEnergy, Dictionary<string, List<object>> robot, long energy)
  103. {
  104. if (energy > maxEnergy)
  105. {
  106. Console.WriteLine("We need more power!");
  107. }
  108.  
  109. else if (robot.Count < 4 || robot["Leg"].Count < 2 || robot["Arm"].Count < 2)
  110. {
  111. Console.WriteLine("We need more parts!");
  112. }
  113.  
  114. else
  115. {
  116. Console.WriteLine("Jarvis:");
  117. Console.WriteLine(string.Join(Environment.NewLine, robot["Head"]));
  118. Console.WriteLine(string.Join(Environment.NewLine, robot["Torso"]));
  119. Console.WriteLine(string.Join(Environment.NewLine, robot["Arm"]));
  120. Console.WriteLine(string.Join(Environment.NewLine, robot["Leg"]));
  121. }
  122. }
  123.  
  124. private static long CalculateComponentsEnergy(Dictionary<string, List<Arms>> arms, Dictionary<string, List<Legs>> legs, Dictionary<string, List<Torso>> torso, Dictionary<string, List<Head>> head, Dictionary<string, List<object>> robot, long energy)
  125. {
  126. foreach (var item in arms)
  127. {
  128. var list = item.Value.ToList();
  129. var temp = list.OrderBy(x => x.EnergyConsumption).Take(2).ToList();
  130. energy += temp.Select(x => x.EnergyConsumption).Sum();
  131.  
  132. if (robot.ContainsKey(item.Key))
  133. {
  134. robot[item.Key].AddRange(temp);
  135. }
  136. }
  137.  
  138. foreach (var item in legs)
  139. {
  140. var list = item.Value.ToList();
  141. var temp = list.OrderBy(x => x.EnergyConsumption).Take(2).ToList();
  142. energy += temp.Select(x => x.EnergyConsumption).Sum();
  143.  
  144. if (robot.ContainsKey(item.Key))
  145. {
  146. robot[item.Key].AddRange(temp);
  147. }
  148. }
  149.  
  150. foreach (var item in head)
  151. {
  152. var list = item.Value.ToList();
  153. var temp = list.OrderBy(x => x.EnergyConsumption).Take(1).ToList();
  154. energy += temp.Select(x => x.EnergyConsumption).Sum();
  155.  
  156. if (robot.ContainsKey(item.Key))
  157. {
  158. robot[item.Key].AddRange(temp);
  159. }
  160. }
  161.  
  162. foreach (var item in torso)
  163. {
  164. var list = item.Value.ToList();
  165. var temp = list.OrderBy(x => x.EnergyConsumption).Take(1).ToList();
  166. energy += temp.Select(x => x.EnergyConsumption).Sum();
  167.  
  168. if (robot.ContainsKey(item.Key))
  169. {
  170. robot[item.Key].AddRange(temp);
  171. }
  172. }
  173.  
  174. return energy;
  175. }
  176.  
  177. private static void AddComponents(Dictionary<string, List<Arms>> arms, Dictionary<string, List<Legs>> legs, Dictionary<string, List<Torso>> torso, Dictionary<string, List<Head>> head, string typeOfComponent, long energyConsumption, string property1, string property2)
  178. {
  179. switch (typeOfComponent)
  180. {
  181. case "Arm":
  182. var arm = new Arms()
  183. {
  184. EnergyConsumption = energyConsumption,
  185. ReachDistance = int.Parse(property1),
  186. CountOfFingers = int.Parse(property2)
  187. };
  188.  
  189. arms[typeOfComponent].Add(arm);
  190. break;
  191. case "Leg":
  192. var leg = new Legs()
  193. {
  194. EnergyConsumption = energyConsumption,
  195. Strenght = int.Parse(property1),
  196. Speed = int.Parse(property2)
  197. };
  198.  
  199. legs[typeOfComponent].Add(leg);
  200. break;
  201. case "Torso":
  202. var torsoTemp = new Torso()
  203. {
  204. EnergyConsumption = energyConsumption,
  205. ProcessorSizeInSentimeters = double.Parse(property1),
  206. HousingMaterial = property2
  207. };
  208.  
  209. torso[typeOfComponent].Add(torsoTemp);
  210. break;
  211. case "Head":
  212. var headTemp = new Head()
  213. {
  214. EnergyConsumption = energyConsumption,
  215. Iq = int.Parse(property1),
  216. SkinMaterial = property2
  217. };
  218.  
  219. head[typeOfComponent].Add(headTemp);
  220. break;
  221. }
  222. }
  223. }
  224. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement