Advertisement
Guest User

Untitled

a guest
Jul 15th, 2017
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.60 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<Leg> 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 Leg
  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<Leg>()
  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.         robot.Arms.Add(currentArm);
  89.     }
  90.  
  91.     private static void AddLeg(Robot robot, string[] split)
  92.     {
  93.         Leg currentLeg = new Leg()
  94.         {
  95.             EnergyConsumption = int.Parse(split[1]),
  96.             Strength = int.Parse(split[2]),
  97.             Speed = int.Parse(split[3])
  98.         };
  99.  
  100.         robot.Legs.Add(currentLeg);
  101.     }
  102.  
  103.     private static void AddTorso(Robot robot, string[] split)
  104.     {
  105.         Torso currentTorso = new Torso()
  106.         {
  107.             EnergyConsumption = int.Parse(split[1]),
  108.             ProcessorSize = decimal.Parse(split[2]),
  109.             HousingMaterial = split[3]
  110.         };
  111.  
  112.         robot.Torsos.Add(currentTorso);
  113.     }
  114.  
  115.     private static void AddHead(Robot robot, string[] split)
  116.     {
  117.         Head currentHead = new Head()
  118.         {
  119.             EnergyConsumption = int.Parse(split[1]),
  120.             IQ = int.Parse(split[2]),
  121.             SkinMaterial = split[3]
  122.         };
  123.  
  124.         robot.Heads.Add(currentHead);
  125.     }
  126.  
  127.     private static long GetPartsSum(Robot robot)
  128.     {
  129.         long armsValue = (robot.Arms.OrderBy(a => a.EnergyConsumption).First().EnergyConsumption + robot.Arms
  130.                               .OrderBy(a => a.EnergyConsumption).Skip(1).Take(1).First().EnergyConsumption);
  131.  
  132.         long torsoValue = robot.Torsos.OrderBy(t => t.EnergyConsumption).First().EnergyConsumption;
  133.  
  134.         long legsValue = (robot.Legs.OrderBy(l => l.EnergyConsumption).First().EnergyConsumption + robot.Legs
  135.                               .OrderBy(l => l.EnergyConsumption).Skip(1).Take(1).First().EnergyConsumption);
  136.  
  137.         long headValue = robot.Heads.OrderBy(h => h.EnergyConsumption).First().EnergyConsumption;
  138.  
  139.         long partsSum = armsValue + torsoValue + legsValue + headValue;
  140.         return partsSum;
  141.     }
  142.  
  143.     private static void PrintingResults(Robot robot, long maximumEnergy)
  144.     {
  145.  
  146.         if (robot.Arms.Count < 2 || robot.Heads.Count == 0 || robot.Torsos.Count == 0 || robot.Legs.Count < 2)
  147.         {
  148.             Console.WriteLine($"We need more parts!");
  149.         }
  150.         else
  151.         {
  152.             long partsSum = GetPartsSum(robot);
  153.  
  154.             if (partsSum > maximumEnergy)
  155.             {
  156.                 Console.WriteLine($"We need more power!");
  157.             }
  158.             else
  159.             {
  160.                 Console.WriteLine($"Jarvis:");
  161.  
  162.                 Head robotHead = robot
  163.                     .Heads
  164.                     .OrderBy(h => h.EnergyConsumption)
  165.                     .Take(1)
  166.                     .First();
  167.  
  168.                 Console.WriteLine($"#Head:");
  169.                 Console.WriteLine($"###Energy consumption: {robotHead.EnergyConsumption}");
  170.                 Console.WriteLine($"###IQ: {robotHead.IQ}");
  171.                 Console.WriteLine($"###Skin material: {robotHead.SkinMaterial}");
  172.  
  173.                 Torso robotTorso = robot
  174.                     .Torsos
  175.                     .OrderBy(t => t.EnergyConsumption)
  176.                     .Take(1)
  177.                     .First();
  178.  
  179.                 Console.WriteLine($"#Torso:");
  180.                 Console.WriteLine($"###Energy consumption: {robotTorso.EnergyConsumption}");
  181.                 Console.WriteLine($"###Processor size: {robotTorso.ProcessorSize:0.0}");
  182.                 Console.WriteLine($"###Corpus material: {robotTorso.HousingMaterial}");
  183.  
  184.                 Arm[] robotArms = robot
  185.                     .Arms
  186.                     .OrderBy(a => a.EnergyConsumption)
  187.                     .Take(2)
  188.                     .ToArray();
  189.  
  190.                 foreach (var arm in robotArms)
  191.                 {
  192.                     Console.WriteLine($"#Arm:");
  193.                     Console.WriteLine($"###Energy consumption: {arm.EnergyConsumption}");
  194.                     Console.WriteLine($"###Reach: {arm.ArmsReach}");
  195.                     Console.WriteLine($"###Fingers: {arm.FingersCount}");
  196.                 }
  197.  
  198.                 Leg[] robotLeg = robot
  199.                     .Legs
  200.                     .OrderBy(l => l.EnergyConsumption)
  201.                     .Take(2)
  202.                     .ToArray();
  203.  
  204.                 foreach (var leg in robotLeg)
  205.                 {
  206.                     Console.WriteLine($"#Leg:");
  207.                     Console.WriteLine($"###Energy consumption: {leg.EnergyConsumption}");
  208.                     Console.WriteLine($"###Strength: {leg.Strength}");
  209.                     Console.WriteLine($"###Speed: {leg.Speed}");
  210.                 }
  211.             }
  212.         }
  213.     }
  214.  
  215.  
  216. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement