private static void PrintResult(Head headOfRobot, Torso torsoOfRobot, List <Arm> armsOfRobot, List <Leg> legsOfRobot) { Console.WriteLine("Jarvis:"); Console.WriteLine("#Head:"); Console.WriteLine($"###Energy consumption: {headOfRobot.EnergyConsumption}"); Console.WriteLine($"###IQ: {headOfRobot.IQ}"); Console.WriteLine($"###Skin material: {headOfRobot.SkinMaterial}"); Console.WriteLine("#Torso:"); Console.WriteLine($"###Energy consumption: {torsoOfRobot.EnergyConsumption}"); Console.WriteLine($"###Processor size: {torsoOfRobot.ProcessorSizeInCentimeters:F1}"); Console.WriteLine($"###Corpus material: {torsoOfRobot.HousingMaterial}"); Arm firstArm = armsOfRobot.First(); Arm secondArm = armsOfRobot.Last(); Console.WriteLine("#Arm:"); Console.WriteLine($"###Energy consumption: {firstArm.EnergyConsumption}"); Console.WriteLine($"###Reach: {firstArm.ArmReachDistance}"); Console.WriteLine($"###Fingers: {firstArm.CountOfFingers}"); Console.WriteLine("#Arm:"); Console.WriteLine($"###Energy consumption: {secondArm.EnergyConsumption}"); Console.WriteLine($"###Reach: {secondArm.ArmReachDistance}"); Console.WriteLine($"###Fingers: {secondArm.CountOfFingers}"); Leg firstLeg = legsOfRobot.First(); Leg secondLeg = legsOfRobot.Last(); Console.WriteLine("#Leg:"); Console.WriteLine($"###Energy consumption: {firstLeg.EnergyConsumption}"); Console.WriteLine($"###Strength: {firstLeg.Strength}"); Console.WriteLine($"###Speed: {firstLeg.Speed}"); Console.WriteLine("#Leg:"); Console.WriteLine($"###Energy consumption: {secondLeg.EnergyConsumption}"); Console.WriteLine($"###Strength: {secondLeg.Strength}"); Console.WriteLine($"###Speed: {secondLeg.Speed}"); }
public void addLeg(Leg leg) { if (Legs == null) { Legs = new List <Leg>(); } if (Legs.Count < 2) { Legs.Add(leg); } else { for (int i = 0; i < this.Legs.Count; i++) { if (Legs[i].Energy > leg.Energy) { Legs.RemoveAt(i); Legs.Add(leg); } } } }
static void Main(string[] args) { ulong maxCapacity = ulong.Parse(Console.ReadLine()); string[] data = Console.ReadLine() .Split(' ') .ToArray(); bool containHead = false; bool containTorso = false; int armCount = 0; int legCount = 0; List <Head> heads = new List <Head>(); List <Torso> torsoes = new List <Torso>(); List <Arm> arms = new List <Arm>(); List <Leg> legs = new List <Leg>(); while (data[0] != "Assemble!") { string component = data[0]; int consumedEnergy = int.Parse(data[1]); if (component == "Head") { Head head = new Head() { EnergyConsumption = consumedEnergy, IQ = int.Parse(data[2]), SkinMaterial = data[3] }; containHead = true; heads.Add(head); } else if (component == "Torso") { Torso torso = new Torso() { EnergyConsumption = consumedEnergy, ProcessorSizeInCentimeters = int.Parse(data[2]), HousingMaterial = data[3] }; containTorso = true; torsoes.Add(torso); } else if (component == "Arm") { Arm arm = new Arm() { EnergyConsumption = consumedEnergy, ArmReachDistance = int.Parse(data[2]), CountOfFingers = int.Parse(data[3]), }; armCount++; arms.Add(arm); } else if (component == "Leg") { Leg leg = new Leg() { EnergyConsumption = consumedEnergy, Strength = int.Parse(data[2]), Speed = int.Parse(data[3]) }; legCount++; legs.Add(leg); } maxCapacity -= (ulong)consumedEnergy; if (maxCapacity <= 0) { Console.WriteLine("We need more power!"); return; } data = Console.ReadLine() .Split(' ') .ToArray(); } if (legCount < 2 || armCount < 2 || containHead == false || containTorso == false) { Console.WriteLine("We need more parts!"); return; } Head headOfRobot = heads.OrderBy(e => e.EnergyConsumption).FirstOrDefault(); Torso torsoOfRobot = torsoes.OrderBy(e => e.EnergyConsumption).FirstOrDefault(); List <Arm> armsOfRobot = arms.OrderBy(e => e.EnergyConsumption).Take(2).ToList(); List <Leg> legsOfRobot = legs.OrderBy(e => e.EnergyConsumption).Take(2).ToList(); PrintResult(headOfRobot, torsoOfRobot, armsOfRobot, legsOfRobot); }
static void Main(string[] args) { ulong maxEnergyCapacity = ulong.Parse(Console.ReadLine()); uint headMinEnergy = uint.MaxValue; uint torsoMinEnergy = uint.MaxValue; uint armMinEnergy = uint.MaxValue; uint legMinEnergy = uint.MaxValue; var arms = new List <Arm>(); var legs = new List <Leg>(); var torso = new Torso(); var head = new Head(); while (true) { var tokens = Console.ReadLine().Split().ToArray(); if (tokens[0] == "Assemble!") { break; } string typeOfComponent = tokens[0]; if (typeOfComponent == "Arm") { uint energyConsumption = uint.Parse(tokens[1]); var armReachDistance = int.Parse(tokens[2]); var fingersCount = int.Parse(tokens[3]); if (energyConsumption < armMinEnergy) { if (arms.Count == 2) { arms.RemoveAt(0); } Arm arm = new Arm(); arm = AddArm(typeOfComponent, energyConsumption, armReachDistance, fingersCount); arms.Add(arm); armMinEnergy = energyConsumption; } } else if (typeOfComponent == "Leg") { uint energyConsumption = uint.Parse(tokens[1]); var strength = int.Parse(tokens[2]); var speed = int.Parse(tokens[3]); if (energyConsumption < legMinEnergy) { if (legs.Count == 2) { legs.RemoveAt(0); } Leg leg = new Leg(); leg = AddLeg(typeOfComponent, energyConsumption, strength, speed); legs.Add(leg); legMinEnergy = energyConsumption; } } else if (typeOfComponent == "Torso") { uint energyConsumption = uint.Parse(tokens[1]); var processorSize = double.Parse(tokens[2]); var housingMaterial = tokens[3]; if (energyConsumption < torsoMinEnergy) { torso = new Torso(); torso = AddTorso(typeOfComponent, energyConsumption, processorSize, housingMaterial); torsoMinEnergy = energyConsumption; } } else if (typeOfComponent == "Head") { uint energyConsumption = uint.Parse(tokens[1]); var iq = int.Parse(tokens[2]); var skinMaterial = tokens[3]; if (energyConsumption < headMinEnergy) { head = new Head(); head = AddHead(typeOfComponent, energyConsumption, iq, skinMaterial); headMinEnergy = energyConsumption; } } } ulong totalEnergyConsumption = head.EnergyConsumption + torso.EnergyConsumption; foreach (var arm in arms) { totalEnergyConsumption += arm.EnergyConsumption; } foreach (var leg in legs) { totalEnergyConsumption += leg.EnergyConsumption; } if (maxEnergyCapacity < totalEnergyConsumption) { Console.WriteLine($"We need more power!"); } else if (head.EnergyConsumption == 0 || torso.EnergyConsumption == 0 || arms.Count < 2 || legs.Count < 2) { Console.WriteLine("We need more parts!"); } else { PrintJarvis(head, torso, arms, legs); } }
static void Main(string[] args) { BigInteger energyCap = BigInteger.Parse(Console.ReadLine()); Head robotHead = new Head(); robotHead.EnergyConsumption = int.MaxValue; List <Arm> robotArms = new List <Arm>(); robotArms.Select(x => x.EnergyConsumption = int.MaxValue); Torso robotTorso = new Torso(); robotTorso.EnergyConsumption = int.MaxValue; List <Leg> robotLegs = new List <Leg>(); robotLegs.Select(x => x.EnergyConsumption = int.MaxValue); string command = Console.ReadLine(); while (command != "Assemble!") { string[] currCommand = command.Split(' ') .ToArray(); Arm currArm = new Arm(); Leg currLeg = new Leg(); string currComponent = currCommand[0].ToLower(); int currEnergyConsum = int.Parse(currCommand[1]); if (currComponent == "head") { int currIQ = int.Parse(currCommand[2]); string currSkinMat = currCommand[3]; if (currEnergyConsum < robotHead.EnergyConsumption) { robotHead.EnergyConsumption = currEnergyConsum; robotHead.IQ = currIQ; robotHead.SkinMaterial = currSkinMat; } } else if (currComponent == "arm") { long currArmReach = long.Parse(currCommand[2]); long currFingersNum = long.Parse(currCommand[3]); currArm.EnergyConsumption = currEnergyConsum; currArm.ArmReachDistance = currArmReach; currArm.CountOfFingers = currFingersNum; if (robotArms.Count < 2) { robotArms.Add(currArm); } else { for (int i = 0; i < robotArms.Count; i++) { if (currArm.EnergyConsumption < robotArms[i].EnergyConsumption) { robotArms.RemoveAt(i); robotArms.Add(currArm); } } } } else if (currComponent == "torso") { double currProcSize = double.Parse(currCommand[2]); string currHousingMaterial = currCommand[3]; if (currEnergyConsum < robotTorso.EnergyConsumption) { robotTorso.EnergyConsumption = currEnergyConsum; robotTorso.ProcSizeInCm = currProcSize; robotTorso.HousingMaterial = currHousingMaterial; } } else if (currComponent == "leg") { long currStrength = long.Parse(currCommand[2]); long currSpeed = long.Parse(currCommand[3]); currLeg.EnergyConsumption = currEnergyConsum; currLeg.Strength = currStrength; currLeg.Speed = currSpeed; if (robotLegs.Count < 2) { robotLegs.Add(currLeg); } else { for (int i = 0; i < robotLegs.Count; i++) { if (currLeg.EnergyConsumption < robotLegs[i].EnergyConsumption) { robotLegs.RemoveAt(i); robotLegs.Add(currLeg); } } } } command = Console.ReadLine(); } if (robotHead.SkinMaterial == null || robotArms.Count < 2 || robotTorso.HousingMaterial == null || robotLegs.Count < 2) { Console.WriteLine("We need more parts!"); return; } List <Arm> sortedArms = new List <Arm>(); List <Leg> sortedLegs = new List <Leg>(); if (robotArms.Count == 2) { sortedArms = robotArms.OrderBy(x => x.EnergyConsumption).ToList(); } if (robotLegs.Count == 2) { sortedLegs = robotLegs.OrderBy(x => x.EnergyConsumption).ToList(); } BigInteger sum = robotHead.EnergyConsumption + robotArms.Select(x => x.EnergyConsumption).Sum() + robotLegs.Select(x => x.EnergyConsumption).Sum() + robotTorso.EnergyConsumption; var diff = energyCap - sum; if (diff >= 0) { Console.WriteLine("Jarvis:"); Console.WriteLine("#Head:"); Console.WriteLine($"###Energy consumption: {robotHead.EnergyConsumption}"); Console.WriteLine($"###IQ: {robotHead.IQ}"); Console.WriteLine($"###Skin material: {robotHead.SkinMaterial}"); Console.WriteLine($"#Torso:"); Console.WriteLine($"###Energy consumption: {robotTorso.EnergyConsumption}"); Console.WriteLine($"###Processor size: {robotTorso.ProcSizeInCm:F1}"); Console.WriteLine($"###Corpus material: {robotTorso.HousingMaterial}"); Console.WriteLine($"#Arm:"); Console.WriteLine($"###Energy consumption: {sortedArms[0].EnergyConsumption}"); Console.WriteLine($"###Reach: {sortedArms[0].ArmReachDistance}"); Console.WriteLine($"###Fingers: {sortedArms[0].CountOfFingers}"); Console.WriteLine($"#Arm:"); Console.WriteLine($"###Energy consumption: {sortedArms[1].EnergyConsumption}"); Console.WriteLine($"###Reach: {sortedArms[1].ArmReachDistance}"); Console.WriteLine($"###Fingers: {sortedArms[1].CountOfFingers}"); Console.WriteLine("#Leg:"); Console.WriteLine($"###Energy consumption: {sortedLegs[0].EnergyConsumption}"); Console.WriteLine($"###Strength: {sortedLegs[0].Strength}"); Console.WriteLine($"###Speed: {sortedLegs[0].Speed}"); Console.WriteLine("#Leg:"); Console.WriteLine($"###Energy consumption: {sortedLegs[1].EnergyConsumption}"); Console.WriteLine($"###Strength: {sortedLegs[1].Strength}"); Console.WriteLine($"###Speed: {sortedLegs[1].Speed}"); return; } else { Console.WriteLine("We need more power!"); return; } }
static void Main(string[] args) { ulong energyCap = ulong.Parse(Console.ReadLine()); Head robotHead = new Head(); robotHead.EnergyConsumption = int.MaxValue; Arm robotLeftArm = new Arm(); robotLeftArm.EnergyConsumption = int.MaxValue; Arm robotRightArm = new Arm(); robotRightArm.EnergyConsumption = int.MaxValue; Torso robotTorso = new Torso(); robotTorso.EnergyConsumption = int.MaxValue; Leg robotLeftLeg = new Leg(); robotLeftLeg.EnergyConsumption = int.MaxValue; Leg robotRightLeg = new Leg(); robotRightLeg.EnergyConsumption = int.MaxValue; int legCounter = -1; int armCounter = -1; string command = Console.ReadLine(); while (command != "Assemble!") { string[] currCommand = command.Split(' ') .ToArray(); //Head head = new Head(); //Arm leftArm = new Arm(); //Arm rightArm = new Arm(); //Torso torso = new Torso(); //Leg leftLeg = new Leg(); //Leg rightLeg = new Leg(); string currComponent = currCommand[0].ToLower(); int currEnergyConsum = int.Parse(currCommand[1]); if (currComponent == "head") { int currIQ = int.Parse(currCommand[2]); string currSkinMat = currCommand[3]; if (currEnergyConsum < robotHead.EnergyConsumption) { robotHead.EnergyConsumption = currEnergyConsum; robotHead.IQ = currIQ; robotHead.SkinMaterial = currSkinMat; } } else if (currComponent == "arm") { int currArmReach = int.Parse(currCommand[2]); int currFingersNum = int.Parse(currCommand[3]); var oldEncons = 0; var oldArmReach = 0; var oldFingers = 0; if (currEnergyConsum < robotLeftArm.EnergyConsumption) { oldEncons = robotLeftArm.EnergyConsumption; oldArmReach = robotLeftArm.ArmReachDistance; oldFingers = robotLeftArm.CountOfFingers; robotLeftArm.EnergyConsumption = currEnergyConsum; robotLeftArm.ArmReachDistance = currArmReach; robotLeftArm.CountOfFingers = currFingersNum; armCounter++; if (armCounter == 0) { continue; } } else if (currEnergyConsum < robotLeftLeg.EnergyConsumption && currEnergyConsum < robotRightLeg.EnergyConsumption) { robotLeftArm.EnergyConsumption = currEnergyConsum; robotLeftArm.ArmReachDistance = currArmReach; robotLeftArm.CountOfFingers = currFingersNum; } robotRightArm.EnergyConsumption = oldEncons; robotRightArm.ArmReachDistance = oldArmReach; robotRightArm.CountOfFingers = oldFingers; } else if (currComponent == "torso") { double currProcSize = double.Parse(currCommand[2]); string currHousingMaterial = currCommand[3]; if (currEnergyConsum < robotTorso.EnergyConsumption) { robotTorso.EnergyConsumption = currEnergyConsum; robotTorso.ProcSizeInCm = currProcSize; robotTorso.HousingMaterial = currHousingMaterial; } } else if (currComponent == "leg") { int currStrength = int.Parse(currCommand[2]); int currSpeed = int.Parse(currCommand[3]); if (currEnergyConsum < robotLeftLeg.EnergyConsumption || currEnergyConsum < robotRightLeg.EnergyConsumption) { var oldEncons = 0; var oldStr = 0; var oldSpeed = 0; if (currEnergyConsum < robotLeftLeg.EnergyConsumption) { oldEncons = robotLeftLeg.EnergyConsumption; oldStr = robotLeftLeg.Strength; oldSpeed = robotLeftLeg.Speed; robotLeftLeg.EnergyConsumption = currEnergyConsum; robotLeftLeg.Strength = currStrength; robotLeftLeg.Speed = currSpeed; legCounter++; if (legCounter == 0) { continue; } } else if (currEnergyConsum < robotLeftLeg.EnergyConsumption && currEnergyConsum < robotRightLeg.EnergyConsumption) { robotLeftLeg.EnergyConsumption = currEnergyConsum; robotLeftLeg.Strength = currStrength; robotLeftLeg.Speed = currSpeed; } robotRightLeg.EnergyConsumption = oldEncons; robotRightLeg.Strength = oldStr; robotRightLeg.Speed = oldSpeed; } } command = Console.ReadLine(); } if ((robotHead.SkinMaterial == null && robotHead.IQ == 0) || (robotLeftArm.EnergyConsumption == int.MaxValue && robotLeftArm.CountOfFingers == 0 && robotLeftArm.ArmReachDistance == 0) || (robotRightArm.EnergyConsumption == int.MaxValue && robotRightArm.CountOfFingers == 0 && robotRightArm.ArmReachDistance == 0) || robotTorso.HousingMaterial == null || (robotLeftLeg.EnergyConsumption == int.MaxValue && robotLeftLeg.Speed == 0 && robotLeftLeg.Strength == 0) || (robotRightLeg.EnergyConsumption == int.MaxValue && robotRightLeg.Speed == 0 && robotRightLeg.Strength == 0)) { Console.WriteLine("We need more parts!"); return; } try { BigInteger sum = (BigInteger)(robotHead.EnergyConsumption + robotLeftArm.EnergyConsumption + robotRightArm.EnergyConsumption + robotTorso.EnergyConsumption + robotLeftLeg.EnergyConsumption + robotRightLeg.EnergyConsumption); var diff = energyCap - sum; if (diff >= 0) { Console.WriteLine("Jarvis:"); Console.WriteLine("#Head:"); Console.WriteLine($"###Energy consumption: {robotHead.EnergyConsumption}"); Console.WriteLine($"###IQ: {robotHead.IQ}"); Console.WriteLine($"###Skin material: {robotHead.SkinMaterial}"); Console.WriteLine($"#Torso:"); Console.WriteLine($"###Energy consumption: {robotTorso.EnergyConsumption}"); Console.WriteLine($"###Processor size: {robotTorso.ProcSizeInCm:F1}"); Console.WriteLine($"###Corpus material: {robotTorso.HousingMaterial}"); Console.WriteLine($"#Arm:"); Console.WriteLine($"###Energy consumption: {robotLeftArm.EnergyConsumption}"); Console.WriteLine($"###Reach: {robotLeftArm.ArmReachDistance}"); Console.WriteLine($"###Fingers: {robotLeftArm.CountOfFingers}"); Console.WriteLine($"#Arm:"); Console.WriteLine($"###Energy consumption: {robotRightArm.EnergyConsumption}"); Console.WriteLine($"###Reach: {robotRightArm.ArmReachDistance}"); Console.WriteLine($"###Fingers: {robotRightArm.CountOfFingers}"); Console.WriteLine("#Leg:"); Console.WriteLine($"###Energy consumption: {robotLeftLeg.EnergyConsumption}"); Console.WriteLine($"###Strength: {robotLeftLeg.Strength}"); Console.WriteLine($"###Speed: {robotLeftLeg.Speed}"); Console.WriteLine("#Leg:"); Console.WriteLine($"###Energy consumption: {robotRightLeg.EnergyConsumption}"); Console.WriteLine($"###Strength: {robotRightLeg.Strength}"); Console.WriteLine($"###Speed: {robotRightLeg.Speed}"); return; } else { throw new Exception(); } } catch (Exception) { Console.WriteLine("We need more power!"); return; } }
static void Main(string[] args) { BigInteger maxEnergy = BigInteger.Parse(Console.ReadLine()); string[] parts = Console.ReadLine().Split(' '); Head[] head = new Head[1]; Torso[] torso = new Torso[1]; Arm[] arms = new Arm[2]; Leg[] legs = new Leg[2]; while (!parts[0].Equals("Assemble!")) { switch (parts[0]) { case "Head": Head newHead = new Head(parts[1], parts[2], parts[3]); if (head[0] == null || head[0].EnergyConsumption > newHead.EnergyConsumption) { head[0] = newHead; } break; case "Torso": Torso newTorso = new Torso(parts[1], parts[2], parts[3]); if (torso[0] == null || torso[0].EnergyConsumption > newTorso.EnergyConsumption) { torso[0] = newTorso; } break; case "Arm": Arm newArm = new Arm(parts[1], parts[2], parts[3]); if (arms[0] == null) { arms[0] = newArm; } else if (arms[1] == null) { arms[1] = newArm; } else { for (int i = 0; i < arms.Length; i++) { if (arms[i].EnergyConsumption > newArm.EnergyConsumption) { arms[i] = newArm; break; } } } break; case "Leg": Leg newLeg = new Leg(parts[1], parts[2], parts[3]); if (legs[0] == null) { legs[0] = newLeg; } else if (legs[1] == null) { legs[1] = newLeg; } else { for (int i = 0; i < legs.Length; i++) { if (legs[i].EnergyConsumption > newLeg.EnergyConsumption) { legs[i] = newLeg; break; } } } break; } parts = Console.ReadLine().Split(' '); } if (arms[1] == null || legs[1] == null || head[0] == null || torso[0] == null) { Console.WriteLine("We need more parts!"); } else { BigInteger energy = arms.Sum(x => x.EnergyConsumption) + legs.Sum(x => x.EnergyConsumption) + torso[0].EnergyConsumption + head[0].EnergyConsumption; if (maxEnergy < energy) { Console.WriteLine("We need more power!"); } else { arms = arms.OrderBy(x => x.EnergyConsumption).ToArray(); legs = legs.OrderBy(x => x.EnergyConsumption).ToArray(); Console.WriteLine($@"Jarvis: #Head: ###Energy consumption: {head[0].EnergyConsumption} ###IQ: {head[0].Iq} ###Skin material: {head[0].SkinMatherial} #Torso: ###Energy consumption: {torso[0].EnergyConsumption} ###Processor size: {torso[0].ProcessorSize:f1} ###Corpus material: {torso[0].HousingMatherial} #Arm: ###Energy consumption: {arms[0].EnergyConsumption} ###Reach: {arms[0].ArmReachDistance} ###Fingers: {arms[0].CountOfFingers} #Arm: ###Energy consumption: {arms[1].EnergyConsumption} ###Reach: {arms[1].ArmReachDistance} ###Fingers: {arms[1].CountOfFingers} #Leg: ###Energy consumption: {legs[0].EnergyConsumption} ###Strength: {legs[0].Strenght} ###Speed: {legs[0].Speed} #Leg: ###Energy consumption: {legs[1].EnergyConsumption} ###Strength: {legs[1].Strenght} ###Speed: {legs[1].Speed}"); } } }