Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class Robot
- {
- public List<Head> Heads { get; set; }
- public List<Torso> Torsos { get; set; }
- public List<Arm> Arms { get; set; }
- public List<Leg> Legs { get; set; }
- }
- class Arm
- {
- public int EnergyConsumption { get; set; }
- public int ArmsReach { get; set; }
- public int FingersCount { get; set; }
- }
- class Leg
- {
- public int EnergyConsumption { get; set; }
- public int Strength { get; set; }
- public int Speed { get; set; }
- }
- class Torso
- {
- public int EnergyConsumption { get; set; }
- public decimal ProcessorSize { get; set; }
- public string HousingMaterial { get; set; }
- }
- class Head
- {
- public int EnergyConsumption { get; set; }
- public int IQ { get; set; }
- public string SkinMaterial { get; set; }
- }
- class Program
- {
- static void Main()
- {
- Robot robot = new Robot()
- {
- Heads = new List<Head>(),
- Torsos = new List<Torso>(),
- Arms = new List<Arm>(),
- Legs = new List<Leg>()
- };
- long maximumEnergy = long.Parse(Console.ReadLine());
- string input = Console.ReadLine();
- while (input != "Assemble!")
- {
- string[] split = input.Split();
- string typeOfComponent = split[0];
- if (typeOfComponent == "Head")
- {
- AddHead(robot, split);
- }
- else if (typeOfComponent == "Torso")
- {
- AddTorso(robot, split);
- }
- else if (typeOfComponent == "Leg")
- {
- AddLeg(robot, split);
- }
- else if (typeOfComponent == "Arm")
- {
- AddArm(robot, split);
- }
- input = Console.ReadLine();
- }
- PrintingResults(robot, maximumEnergy);
- }
- private static void AddArm(Robot robot, string[] split)
- {
- Arm currentArm = new Arm()
- {
- EnergyConsumption = int.Parse(split[1]),
- ArmsReach = int.Parse(split[2]),
- FingersCount = int.Parse(split[3])
- };
- robot.Arms.Add(currentArm);
- }
- private static void AddLeg(Robot robot, string[] split)
- {
- Leg currentLeg = new Leg()
- {
- EnergyConsumption = int.Parse(split[1]),
- Strength = int.Parse(split[2]),
- Speed = int.Parse(split[3])
- };
- robot.Legs.Add(currentLeg);
- }
- private static void AddTorso(Robot robot, string[] split)
- {
- Torso currentTorso = new Torso()
- {
- EnergyConsumption = int.Parse(split[1]),
- ProcessorSize = decimal.Parse(split[2]),
- HousingMaterial = split[3]
- };
- robot.Torsos.Add(currentTorso);
- }
- private static void AddHead(Robot robot, string[] split)
- {
- Head currentHead = new Head()
- {
- EnergyConsumption = int.Parse(split[1]),
- IQ = int.Parse(split[2]),
- SkinMaterial = split[3]
- };
- robot.Heads.Add(currentHead);
- }
- private static long GetPartsSum(Robot robot)
- {
- long armsValue = (robot.Arms.OrderBy(a => a.EnergyConsumption).First().EnergyConsumption + robot.Arms
- .OrderBy(a => a.EnergyConsumption).Skip(1).Take(1).First().EnergyConsumption);
- long torsoValue = robot.Torsos.OrderBy(t => t.EnergyConsumption).First().EnergyConsumption;
- long legsValue = (robot.Legs.OrderBy(l => l.EnergyConsumption).First().EnergyConsumption + robot.Legs
- .OrderBy(l => l.EnergyConsumption).Skip(1).Take(1).First().EnergyConsumption);
- long headValue = robot.Heads.OrderBy(h => h.EnergyConsumption).First().EnergyConsumption;
- long partsSum = armsValue + torsoValue + legsValue + headValue;
- return partsSum;
- }
- private static void PrintingResults(Robot robot, long maximumEnergy)
- {
- if (robot.Arms.Count < 2 || robot.Heads.Count == 0 || robot.Torsos.Count == 0 || robot.Legs.Count < 2)
- {
- Console.WriteLine($"We need more parts!");
- }
- else
- {
- long partsSum = GetPartsSum(robot);
- if (partsSum > maximumEnergy)
- {
- Console.WriteLine($"We need more power!");
- }
- else
- {
- Console.WriteLine($"Jarvis:");
- Head robotHead = robot
- .Heads
- .OrderBy(h => h.EnergyConsumption)
- .Take(1)
- .First();
- Console.WriteLine($"#Head:");
- Console.WriteLine($"###Energy consumption: {robotHead.EnergyConsumption}");
- Console.WriteLine($"###IQ: {robotHead.IQ}");
- Console.WriteLine($"###Skin material: {robotHead.SkinMaterial}");
- Torso robotTorso = robot
- .Torsos
- .OrderBy(t => t.EnergyConsumption)
- .Take(1)
- .First();
- Console.WriteLine($"#Torso:");
- Console.WriteLine($"###Energy consumption: {robotTorso.EnergyConsumption}");
- Console.WriteLine($"###Processor size: {robotTorso.ProcessorSize:0.0}");
- Console.WriteLine($"###Corpus material: {robotTorso.HousingMaterial}");
- Arm[] robotArms = robot
- .Arms
- .OrderBy(a => a.EnergyConsumption)
- .Take(2)
- .ToArray();
- foreach (var arm in robotArms)
- {
- Console.WriteLine($"#Arm:");
- Console.WriteLine($"###Energy consumption: {arm.EnergyConsumption}");
- Console.WriteLine($"###Reach: {arm.ArmsReach}");
- Console.WriteLine($"###Fingers: {arm.FingersCount}");
- }
- Leg[] robotLeg = robot
- .Legs
- .OrderBy(l => l.EnergyConsumption)
- .Take(2)
- .ToArray();
- foreach (var leg in robotLeg)
- {
- Console.WriteLine($"#Leg:");
- Console.WriteLine($"###Energy consumption: {leg.EnergyConsumption}");
- Console.WriteLine($"###Strength: {leg.Strength}");
- Console.WriteLine($"###Speed: {leg.Speed}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement