Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.42 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Numerics;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Jarvis
  9. {
  10. class Arms
  11. {
  12. public int EnergyConsumption { get; set; }
  13. public int ArmReachDistance { get; set; }
  14. public int CountOfFingers { get; set; }
  15. public DateTime MomentOfCreation { get; set; }
  16. }
  17.  
  18. class Legs
  19. {
  20. public int EnergyConsumption { get; set; }
  21. public int Strength { get; set; }
  22. public int Speed { get; set; }
  23. public DateTime MomentOfCreation { get; set; }
  24. }
  25.  
  26. class Torso
  27. {
  28. public int EnergyConsumption { get; set; }
  29. public double ProcessorSizeInCentimeters { get; set; }
  30. public string HousingMaterial { get; set; }
  31. }
  32.  
  33. class Head
  34. {
  35. public int EnergyConsumption { get; set; }
  36. public int IQ { get; set; }
  37. public string SkinMaterial { get; set; }
  38. }
  39.  
  40. class Robot
  41. {
  42. public Arms[] Arms { get; set; }
  43. public Legs[] Legs { get; set; }
  44. public Torso Torso { get; set; }
  45. public Head Head { get; set; }
  46. }
  47. class Program
  48. {
  49. static void Main(string[] args)
  50. {
  51. Robot jarvis = new Robot();
  52. jarvis.Arms = new Arms[2];
  53. jarvis.Legs = new Legs[2];
  54. //jarvis = InitialRobot(jarvis);
  55. ulong power = ulong.Parse(Console.ReadLine());
  56. jarvis = MakeRobot(jarvis);
  57. PrintResult(jarvis, power);
  58. }
  59.  
  60. private static void PrintResult(Robot jarvis, ulong power)
  61. {
  62.  
  63.  
  64. if (jarvis.Head == null || jarvis.Torso == null || jarvis.Legs[0] == null || jarvis.Legs[1] == null || jarvis.Arms[0] == null || jarvis.Arms[1] == null)
  65. {
  66. Console.WriteLine("We need more parts!");
  67. }
  68. else
  69. {
  70. BigInteger totalEnergyNeeded = jarvis.Head.EnergyConsumption + jarvis.Torso.EnergyConsumption + jarvis.Arms[0].EnergyConsumption + jarvis.Arms[1].EnergyConsumption
  71. + jarvis.Legs[0].EnergyConsumption + jarvis.Legs[1].EnergyConsumption;
  72. if (totalEnergyNeeded > power)
  73. {
  74. Console.WriteLine("We need more power!");
  75. }
  76.  
  77. else
  78. {
  79. Console.WriteLine("Jarvis:");
  80. Console.WriteLine("#Head:");
  81. Console.WriteLine($"###Energy consumption: {jarvis.Head.EnergyConsumption}");
  82. Console.WriteLine($"###IQ: {jarvis.Head.IQ}");
  83. Console.WriteLine($"###Skin material: {jarvis.Head.SkinMaterial}");
  84. Console.WriteLine("#Torso:");
  85. Console.WriteLine($"###Energy consumption: {jarvis.Torso.EnergyConsumption}");
  86. Console.WriteLine($"###Processor size: {jarvis.Torso.ProcessorSizeInCentimeters:f1}");
  87. Console.WriteLine($"###Corpus material: {jarvis.Torso.HousingMaterial}");
  88. foreach (var arm in jarvis.Arms.OrderBy(encon => encon.EnergyConsumption))
  89. {
  90. Console.WriteLine($"#Arm:");
  91. Console.WriteLine($"###Energy consumption: {arm.EnergyConsumption}");
  92. Console.WriteLine($"###Reach: {arm.ArmReachDistance}");
  93. Console.WriteLine($"###Fingers: {arm.CountOfFingers}");
  94. }
  95. foreach (var leg in jarvis.Legs.OrderBy(encon => encon.EnergyConsumption))
  96. {
  97. Console.WriteLine($"#Leg:");
  98. Console.WriteLine($"###Energy consumption: {leg.EnergyConsumption}");
  99. Console.WriteLine($"###Strength: {leg.Strength}");
  100. Console.WriteLine($"###Speed: {leg.Speed}");
  101. }
  102. }
  103.  
  104. }
  105. }
  106.  
  107. private static Robot InitialRobot(Robot jarvis)
  108. {
  109. jarvis.Arms = new Arms[2];
  110. jarvis.Legs = new Legs[2];
  111. return jarvis;
  112. }
  113.  
  114. private static Robot MakeRobot(Robot jarvis)
  115. {
  116.  
  117. do
  118. {
  119. string input = Console.ReadLine();
  120. string[] splittedLine = input.Split();
  121. if (input.ToLower() == "assemble!")
  122. {
  123. break;
  124. }
  125. if (splittedLine[0].ToLower() == "arm")
  126. {
  127. Arms currentArm = new Arms();
  128. currentArm = GetArms(splittedLine, currentArm);
  129. if (jarvis.Arms[0] == null || jarvis.Arms[1] == null)
  130. {
  131. if (jarvis.Arms[0] == null)
  132. {
  133. jarvis.Arms[0] = currentArm;
  134. }
  135. else
  136. {
  137. jarvis.Arms[1] = currentArm;
  138. }
  139. }
  140. else if ((currentArm.EnergyConsumption < jarvis.Arms[0].EnergyConsumption && currentArm.EnergyConsumption < jarvis.Arms[1].EnergyConsumption) || currentArm.EnergyConsumption == jarvis.Arms[0].EnergyConsumption && (currentArm.CountOfFingers > jarvis.Arms[0].CountOfFingers || currentArm.CountOfFingers > jarvis.Arms[0].CountOfFingers))
  141. {
  142. if (jarvis.Arms[0].MomentOfCreation < jarvis.Arms[1].MomentOfCreation)
  143. {
  144. jarvis.Arms[0] = currentArm;
  145. }
  146. else
  147. {
  148. jarvis.Arms[1] = currentArm;
  149. }
  150. }
  151. else if (currentArm.EnergyConsumption < jarvis.Arms[0].EnergyConsumption)
  152. {
  153. jarvis.Arms[0] = currentArm;
  154. }
  155. else if (currentArm.EnergyConsumption < jarvis.Arms[1].EnergyConsumption)
  156. {
  157. jarvis.Arms[1] = currentArm;
  158. }
  159.  
  160. }
  161. else if (splittedLine[0].ToLower() == "leg")
  162. {
  163. Legs currentLeg = new Legs();
  164. currentLeg = GetLegs(splittedLine, currentLeg);
  165. if (jarvis.Legs[0] == null || jarvis.Legs[1] == null)
  166. {
  167. if (jarvis.Legs[0] == null)
  168. {
  169. jarvis.Legs[0] = currentLeg;
  170. }
  171. else
  172. {
  173. jarvis.Legs[1] = currentLeg;
  174. }
  175. }
  176. else if (currentLeg.EnergyConsumption < jarvis.Legs[0].EnergyConsumption && currentLeg.EnergyConsumption < jarvis.Legs[1].EnergyConsumption)
  177. {
  178. if (jarvis.Legs[0].MomentOfCreation < jarvis.Legs[1].MomentOfCreation)
  179. {
  180. jarvis.Legs[0] = currentLeg;
  181. }
  182. else
  183. {
  184. jarvis.Legs[1] = currentLeg;
  185. }
  186. }
  187. else if (currentLeg.EnergyConsumption < jarvis.Legs[0].EnergyConsumption)
  188. {
  189. jarvis.Legs[0] = currentLeg;
  190. }
  191. else if (currentLeg.EnergyConsumption < jarvis.Legs[1].EnergyConsumption)
  192. {
  193. jarvis.Legs[1] = currentLeg;
  194. }
  195. }
  196. else if (splittedLine[0].ToLower() == "torso")
  197. {
  198. Torso currentTorso = new Torso();
  199. currentTorso = GetTorso(splittedLine, currentTorso);
  200. if (jarvis.Torso == null)
  201. {
  202. jarvis.Torso = currentTorso;
  203. }
  204. else if (currentTorso.EnergyConsumption < jarvis.Torso.EnergyConsumption)
  205. {
  206. jarvis.Torso = currentTorso;
  207. }
  208. }
  209. else if (splittedLine[0].ToLower() == "head")
  210. {
  211. Head currentHead = new Head();
  212. currentHead = GetHead(splittedLine, currentHead);
  213. if (jarvis.Head == null)
  214. {
  215. jarvis.Head = currentHead;
  216. }
  217. else if (currentHead.EnergyConsumption < jarvis.Head.EnergyConsumption)
  218. {
  219. jarvis.Head = currentHead;
  220. }
  221. }
  222.  
  223. } while (true);
  224. return jarvis;
  225. }
  226.  
  227. private static Head GetHead(string[] splittedLine, Head currentHead)
  228. {
  229. currentHead.EnergyConsumption = int.Parse(splittedLine[1]);
  230. currentHead.IQ = int.Parse(splittedLine[2]);
  231. currentHead.SkinMaterial = splittedLine[3];
  232. return currentHead;
  233. }
  234.  
  235. private static Torso GetTorso(string[] splittedLine, Torso currentTorso)
  236. {
  237. currentTorso.EnergyConsumption = int.Parse(splittedLine[1]);
  238. currentTorso.ProcessorSizeInCentimeters = double.Parse(splittedLine[2]);
  239. currentTorso.HousingMaterial = splittedLine[3];
  240. return currentTorso;
  241. }
  242.  
  243. private static Legs GetLegs(string[] splittedLine, Legs currentLeg)
  244. {
  245. currentLeg.EnergyConsumption = int.Parse(splittedLine[1]);
  246. currentLeg.Strength = int.Parse(splittedLine[2]);
  247. currentLeg.Speed = int.Parse(splittedLine[3]);
  248. currentLeg.MomentOfCreation = DateTime.Now;
  249. return currentLeg;
  250. }
  251.  
  252. private static Arms GetArms(string[] splittedLine, Arms currentArm)
  253. {
  254. currentArm.EnergyConsumption = int.Parse(splittedLine[1]);
  255. currentArm.ArmReachDistance = int.Parse(splittedLine[2]);
  256. currentArm.CountOfFingers = int.Parse(splittedLine[3]);
  257. currentArm.MomentOfCreation = DateTime.Now;
  258. return currentArm;
  259. }
  260.  
  261. }
  262. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement