Guest User

Jarvis

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