public override string ToString() { if (Head == null || Torso == null || Arms.Count < 2 || Legs.Count < 2) { return("We need more parts!"); } ulong totalEnergy = 0L; totalEnergy += Head.HeadEnergy; totalEnergy += Torso.TorsoEnergy; totalEnergy += Arms.Select(a => a.ArmsEnergy).Sum(); totalEnergy += Legs.Select(a => a.Energy).Sum(); if (totalEnergy > Energy) { return("We need more power!"); } StringBuilder sb = new StringBuilder(); sb.Append("Jarvis:\r\n"); sb.Append(Head.ToString()); sb.Append(Torso.ToString()); foreach (Arms arm in Arms.OrderBy(a => a.ArmsEnergy)) { sb.Append(arm.ToString()); } foreach (Legs leg in Legs.OrderBy(a => a.Energy)) { sb.Append(leg.ToString()); } return(base.ToString()); }
public void AddTorso(Torso torsoInput) { if (torsoInput.TorsoEnergy < Torso.TorsoEnergy) { Torso = torsoInput; } }
public override string ToString() { if (Head == null || Torso == null || Arms == null || Legs == null || Arms.Count < 2 || Legs.Count < 2) { return("We need more parts!"); } else if (EnergyCapacity - (Head.Energy + Torso.Energy + Arms.Select(a => a.Energy).Sum() + Legs.Select(a => a.Energy).Sum()) < 0) { return("We need more power!"); } else { StringBuilder output = new StringBuilder(); output.Append("Jarvis:\r\n"); output.Append(Head.ToString()); output.Append(Torso.ToString()); foreach (var arm in Arms.OrderBy(a => a.Energy)) { output.Append(arm.ToString()); } foreach (var leg in Legs.OrderBy(a => a.Energy)) { output.Append(leg.ToString()); } return(output.ToString()); } }
public void AddTorso(Torso torsoInput) { if (Torso == null || torsoInput.Energy < Torso.Energy) { Torso = torsoInput; } }
private static void PrintJarvis(Head head, Torso torso, List <Arm> arms, List <Leg> legs) { Console.WriteLine("Jarvis:"); Console.WriteLine($"#Head:"); Console.WriteLine($"###Energy consumption: {head.EnergyConsumption}"); Console.WriteLine($"###IQ: {head.Iq}"); Console.WriteLine($"###Skin material: {head.SkinMaterial}"); Console.WriteLine($"#Torso:"); Console.WriteLine($"###Energy consumption: {torso.EnergyConsumption}"); Console.WriteLine($"###Processor size: {torso.ProcessorSizeInCentimeters:f1}"); Console.WriteLine($"###Corpus material: {torso.HousingMaterial}"); foreach (var arm in arms.OrderBy(x => x.EnergyConsumption)) { Console.WriteLine($"#Arm:"); Console.WriteLine($"###Energy consumption: {arm.EnergyConsumption}"); Console.WriteLine($"###Reach: {arm.ArmReachDistance}"); Console.WriteLine($"###Fingers: {arm.FingersCount}"); } foreach (var leg in legs.OrderBy(x => x.EnergyConsumption)) { Console.WriteLine($"#Leg:"); Console.WriteLine($"###Energy consumption: {leg.EnergyConsumption}"); Console.WriteLine($"###Strength: {leg.Strength}"); Console.WriteLine($"###Speed: {leg.Speed}"); } }
public static void PrintTorso(Torso Torso) { Console.WriteLine("#Torso:"); Console.WriteLine($"###Energy consumption: {Torso.EnergyConsumption}"); Console.WriteLine($"###Processor size: {Torso.ProcessorSize:f1}"); Console.WriteLine($"###Corpus material: {Torso.HousingMaterial}"); }
static void Main() { long jarvisEnergy = long.Parse(Console.ReadLine()); Jarvis jarvis = new Jarvis(); jarvis.Energy = jarvisEnergy; while (true) { string[] tokens = Console.ReadLine().Split(); if (tokens[0] == "Assemble!") { break; } switch (tokens[0]) { case "Head": Head head = new Head() { Energy = int.Parse(tokens[1]), Iq = int.Parse(tokens[2]), Material = tokens[3] }; jarvis.addHead(head); break; case "Torso": Torso torso = new Torso() { Energy = int.Parse(tokens[1]), ProcessorSize = double.Parse(tokens[2]), Material = tokens[3] }; jarvis.addTorso(torso); break; case "Leg": Leg leg = new Leg() { Energy = int.Parse(tokens[1]), Strenght = int.Parse(tokens[2]), Speed = int.Parse(tokens[3]), }; jarvis.addLeg(leg); break; case "Arm": Arm arm = new Arm() { Energy = int.Parse(tokens[1]), Reach = int.Parse(tokens[2]), Fingers = int.Parse(tokens[3]), }; jarvis.addArm(arm); break; } } Console.WriteLine(jarvis.ToString()); }
public Robot(string maxEnergy, Head head, Torso torso, List <Arm> arms, List <Leg> legs) { MaxEnergy = BigInteger.Parse(maxEnergy); Head = head; Torso = torso; this.Arms = arms.OrderBy(x => x.Enegry).Take(2).ToArray(); this.Legs = legs.OrderBy(x => x.Energy).Take(2).ToArray(); }
public void addTorso(Torso torsoInput) { if (Torso == null) { Torso = torsoInput; } if (torsoInput.Energy < Torso.Energy) { Torso = torsoInput; } }
private static Torso AddTorso(string typeOfComponent, uint energyConsumption, double processorSize, string housingMaterial) { Torso torso = new Torso() { EnergyConsumption = energyConsumption, ProcessorSizeInCentimeters = processorSize, HousingMaterial = housingMaterial }; return(torso); }
private static void AddComponents(Dictionary <string, List <Arms> > arms, Dictionary <string, List <Legs> > legs, Dictionary <string, List <Torso> > torso, Dictionary <string, List <Head> > head, string typeOfComponent, long energyConsumption, string property1, string property2) { switch (typeOfComponent) { case "Arm": var arm = new Arms() { EnergyConsumption = energyConsumption, ReachDistance = int.Parse(property1), CountOfFingers = int.Parse(property2) }; arms[typeOfComponent].Add(arm); break; case "Leg": var leg = new Legs() { EnergyConsumption = energyConsumption, Strenght = int.Parse(property1), Speed = int.Parse(property2) }; legs[typeOfComponent].Add(leg); break; case "Torso": var torsoTemp = new Torso() { EnergyConsumption = energyConsumption, ProcessorSizeInSentimeters = double.Parse(property1), HousingMaterial = property2 }; torso[typeOfComponent].Add(torsoTemp); break; case "Head": var headTemp = new Head() { EnergyConsumption = energyConsumption, Iq = int.Parse(property1), SkinMaterial = property2 }; head[typeOfComponent].Add(headTemp); break; } }
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}"); }
static void Main(string[] args) { string maxEnergy = Console.ReadLine(); List <Arm> arms = new List <Arm>(); List <Leg> legs = new List <Leg>(); List <Head> heads = new List <Head>(); List <Torso> torsos = new List <Torso>(); while (true) { string[] input = Console.ReadLine().Split(); if (input[0] == "Assemble!") { break; } GetRobotParts(input, arms, legs, heads, torsos); } Console.WriteLine(new Robot(maxEnergy, Head.GetLowestEnergyPart(heads), Torso.GetLowestEnergyPart(torsos), arms, legs)); }
static void AddingBodyParts(string[] input, Robot robot) { //HEAD if (input[0] == "Head") { Head currHead = new Head(); currHead.EnergyConsmp = int.Parse(input[1]); currHead.IQ = int.Parse(input[2]); currHead.SkinMaterial = input[3]; if (robot.Heads == null) { robot.Heads = new List <Head>(); } robot.Heads.Add(currHead); // probvai ako e = dali trqbva da se smenq if (robot.Heads.Any(x => x.EnergyConsmp > currHead.EnergyConsmp)) { robot.Heads.Clear(); robot.Heads.Add(currHead); } } else if (input[0] == "Leg") { Legs currLeg = new Legs(); currLeg.EnergyConsmp = int.Parse(input[1]); currLeg.Strenght = int.Parse(input[2]); currLeg.Speed = int.Parse(input[3]); if (robot.Legs == null) { robot.Legs = new List <Legs>(); } robot.Legs.Add(currLeg); } else if (input[0] == "Torso") { Torso currTorso = new Torso(); currTorso.EnergyConsmp = int.Parse(input[1]); currTorso.ProcessorSize = double.Parse(input[2]); currTorso.HousingMaterial = input[3]; if (robot.Torsos == null) { robot.Torsos = new List <Torso>(); } robot.Torsos.Add(currTorso); if (robot.Torsos.Any(x => x.EnergyConsmp > currTorso.EnergyConsmp)) { robot.Torsos.Clear(); robot.Torsos.Add(currTorso); } } else if (input[0] == "Arm") { Arms currArm = new Arms(); currArm.EnergyConsmp = int.Parse(input[1]); currArm.ReachDistance = int.Parse(input[2]); currArm.CountOfFingers = int.Parse(input[3]); if (robot.Arms == null) { robot.Arms = new List <Arms>(); } robot.Arms.Add(currArm); } }
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) { var energyCapacity = long.Parse(Console.ReadLine()); var classJarvis = new Jarvis(); classJarvis.EnergyCapacity = energyCapacity; while (true) { var input = Console.ReadLine().Split(); if (input[0] == "Assemble!") { break; } var component = input[0]; var energyConsuption = int.Parse(input[1]); var property1 = input[2]; var property2 = input[3]; switch (component) { case "Head": var classHead = new Head() { Energy = energyConsuption, Iq = int.Parse(property1), Material = property2 }; classJarvis.AddHead(classHead); break; case "Torso": var classTorso = new Torso() { Energy = energyConsuption, Processor = double.Parse(property1), Material = property2 }; classJarvis.AddTorso(classTorso); break; case "Arm": var classArms = new Arms() { Energy = energyConsuption, Reach = int.Parse(property1), Fingers = int.Parse(property2) }; classJarvis.AddArms(classArms); break; case "Leg": var classLegs = new Legs() { Energy = energyConsuption, Strength = int.Parse(property1), Speed = int.Parse(property2) }; classJarvis.AddLegs(classLegs); break; default: break; } } Console.WriteLine(classJarvis.ToString()); }
public static void Main() { var totalEnergy = long.Parse(Console.ReadLine()); var robot = new Robot(); while (true) { var line = Console.ReadLine().Split(); if (line[0] == "Assemble!") { break; } var part = line[0]; var currEnergyCons = int.Parse(line[1]); if (part == "Head") { var currentHead = new Head(); currentHead.EnergyConsumption = currEnergyCons; currentHead.IQ = int.Parse(line[2]); currentHead.Material = line[3]; if (robot.Heads == null) { robot.Heads = new List <Head>(); } robot.Heads.Add(currentHead); } else if (part == "Torso") { var currentTorso = new Torso(); currentTorso.EnergyConsumption = currEnergyCons; currentTorso.ProcessorSize = decimal.Parse(line[2]); currentTorso.Material = line[3]; if (robot.Torsos == null) { robot.Torsos = new List <Torso>(); } robot.Torsos.Add(currentTorso); } else if (part == "Arm") { var currArm = new Arms(); currArm.EnergyConsumption = currEnergyCons; currArm.ArmsLenght = int.Parse(line[2]); currArm.CountFingers = int.Parse(line[3]); if (robot.Arms == null) { robot.Arms = new List <Arms>(); } robot.Arms.Add(currArm); } else if (part == "Leg") { var currLeg = new Legs(); currLeg.EnergyConsumption = currEnergyCons; currLeg.Strenght = int.Parse(line[2]); currLeg.Speed = int.Parse(line[3]); if (robot.Legs == null) { robot.Legs = new List <Legs>(); } robot.Legs.Add(currLeg); } } if (robot.Arms == null) { robot.Arms = new List <Arms>(); } if (robot.Legs == null) { robot.Legs = new List <Legs>(); } if (robot.Heads == null) { robot.Heads = new List <Head>(); } if (robot.Torsos == null) { robot.Torsos = new List <Torso>(); } if (robot.Arms.Count > 1 && robot.Heads.Count > 0 && robot.Legs.Count > 1 && robot.Torsos.Count > 0) { long consumedEnergy = robot.Arms.OrderBy(x => x.EnergyConsumption).First().EnergyConsumption + robot.Arms.OrderBy(x => x.EnergyConsumption).Skip(1).Take(1).First().EnergyConsumption + robot.Legs.OrderBy(x => x.EnergyConsumption).First().EnergyConsumption + robot.Legs.OrderBy(x => x.EnergyConsumption).Skip(1).Take(1).First().EnergyConsumption + robot.Heads.OrderBy(x => x.EnergyConsumption).First().EnergyConsumption + robot.Torsos.OrderBy(x => x.EnergyConsumption).First().EnergyConsumption; if (consumedEnergy > totalEnergy) { Console.WriteLine("We need more power!"); } else { Console.WriteLine("Jarvis:"); foreach (var item in robot.Heads.OrderBy(x => x.EnergyConsumption).Take(1)) { Console.WriteLine($"#Head:"); Console.WriteLine($"###Energy consumption: {item.EnergyConsumption}"); Console.WriteLine($"###IQ: {item.IQ}"); Console.WriteLine($"###Skin material: {item.Material}"); } foreach (var item in robot.Torsos.OrderBy(x => x.EnergyConsumption).Take(1)) { Console.WriteLine($"#Torso:"); Console.WriteLine($"###Energy consumption: {item.EnergyConsumption}"); Console.WriteLine($"###Processor size: {item.ProcessorSize:f1}"); Console.WriteLine($"###Corpus material: {item.Material}"); } foreach (var item in robot.Arms.OrderBy(x => x.EnergyConsumption) .Take(2)) { Console.WriteLine($"#Arm:"); Console.WriteLine($"###Energy consumption: {item.EnergyConsumption}"); Console.WriteLine($"###Reach: {item.ArmsLenght}"); Console.WriteLine($"###Fingers: {item.CountFingers}"); } foreach (var item in robot.Legs.OrderBy(x => x.EnergyConsumption) .Take(2)) { Console.WriteLine($"#Leg:"); Console.WriteLine($"###Energy consumption: {item.EnergyConsumption}"); Console.WriteLine($"###Strength: {item.Strenght}"); Console.WriteLine($"###Speed: {item.Speed}"); } } } else { Console.WriteLine("We need more parts!"); } }
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; } }
public static void Main() { var maxEnergyCapacity = long.Parse(Console.ReadLine()); var robot = new Robot(); while (true) { var input = Console.ReadLine().Split().ToArray(); if (input[0] == "Assemble!") { break; } var energyConsumption = int.Parse(input[1]); if (input[0] == "Head") { var IQ = int.Parse(input[2]); var currHead = new Head(); currHead.EnergyConsumption = energyConsumption; currHead.IQ = IQ; currHead.SkinMaterial = input[3]; if (robot.Head == null) { robot.Head = new List <Head>(); } robot.Head.Add(currHead); } else if (input[0] == "Arm") { var currentArm = new Arms(); currentArm.EnergyConsumption = energyConsumption; currentArm.ArmReachDistance = int.Parse(input[2]); currentArm.FingersCount = int.Parse(input[3]); if (robot.Arms == null) { robot.Arms = new List <Arms>(); } robot.Arms.Add(currentArm); } else if (input[0] == "Leg") { var currLeg = new Legs(); currLeg.EnergyConsumption = energyConsumption; currLeg.Strength = int.Parse(input[2]); currLeg.Speed = int.Parse(input[3]); if (robot.Legs == null) { robot.Legs = new List <Legs>(); } robot.Legs.Add(currLeg); } else if (input[0] == "Torso") { var torso = new Torso(); torso.EnergyConsumption = energyConsumption; torso.ProcessorSizeSM = decimal.Parse(input[2]); torso.HousingMaterial = input[3]; if (robot.Torso == null) { robot.Torso = new List <Torso>(); } robot.Torso.Add(torso); } } if (robot.Head == null) { robot.Head = new List <Head>(); } if (robot.Arms == null) { robot.Arms = new List <Arms>(); } if (robot.Legs == null) { robot.Legs = new List <Legs>(); } if (robot.Torso == null) { robot.Torso = new List <Torso>(); } if (robot.Head.Count > 0 && robot.Arms.Count > 1 && robot.Legs.Count > 1 && robot.Torso.Count > 0) { long totalEnergyConsumed = robot.Head.OrderBy(h => h.EnergyConsumption).First().EnergyConsumption + robot.Arms.OrderBy(a => a.EnergyConsumption).First().EnergyConsumption + robot.Arms.OrderBy(a => a.EnergyConsumption).Skip(1).Take(1).First() .EnergyConsumption + robot.Legs.OrderBy(l => l.EnergyConsumption).First().EnergyConsumption + robot.Legs.OrderBy(l => l.EnergyConsumption).Skip(1).Take(1).First() .EnergyConsumption + robot.Torso.OrderBy(t => t.EnergyConsumption).First().EnergyConsumption; if (totalEnergyConsumed > maxEnergyCapacity) { Console.WriteLine("We need more power!"); } else { Console.WriteLine("Jarvis:\n#Head:"); foreach (var head in robot.Head.OrderBy(h => h.EnergyConsumption).Take(1)) { Console.WriteLine($"###Energy consumption: {head.EnergyConsumption}"); Console.WriteLine($"###IQ: {head.IQ}"); Console.WriteLine($"###Skin material: {head.SkinMaterial}"); } Console.WriteLine("#Torso:"); foreach (var torso in robot.Torso.OrderBy(t => t.EnergyConsumption).Take(1)) { Console.WriteLine($"###Energy consumption: {torso.EnergyConsumption}"); Console.WriteLine($"###Processor size: {torso.ProcessorSizeSM:f1}"); Console.WriteLine($"###Corpus material: {torso.HousingMaterial}"); } foreach (var arm in robot.Arms.OrderBy(a => a.EnergyConsumption).Take(2)) { Console.WriteLine("#Arm:"); Console.WriteLine($"###Energy consumption: {arm.EnergyConsumption}"); Console.WriteLine($"###Reach: {arm.ArmReachDistance}"); Console.WriteLine($"###Fingers: {arm.FingersCount}"); } foreach (var leg in robot.Legs.OrderBy(l => l.EnergyConsumption).Take(2)) { Console.WriteLine("#Leg:"); Console.WriteLine($"###Energy consumption: {leg.EnergyConsumption}"); Console.WriteLine($"###Strength: {leg.Strength}"); Console.WriteLine($"###Speed: {leg.Speed}"); } } } else { Console.WriteLine("We need more parts!"); } }
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; } }
public static void Main() { var maximumEnergyCapacity = long.Parse(Console.ReadLine()); var FirstLeg = new FirstLeg(); var SecondLeg = new SecondLeg(); var FirstArm = new FirstArm(); var SecondArm = new SecondArm(); var Head = new Head(); var Torso = new Torso(); var torsoCounter = 0; var legsCount = 0; var armsCount = 0; var headCounter = 0; var data = Console.ReadLine(); while (data != "Assemble!") { var args = data.Split(); var typeOfComponent = args[0]; var energyConsumption = int.Parse(args[1]); var firstProperty = args[2]; var secondProperty = args[3]; if (typeOfComponent == "Leg") { if (legsCount == 0) { legsCount = 1; FirstLeg.EnergyConsumption = energyConsumption; FirstLeg.Strength = int.Parse(firstProperty); FirstLeg.Speed = int.Parse(secondProperty); } else if (legsCount == 1) { legsCount = 2; SecondLeg.EnergyConsumption = energyConsumption; SecondLeg.Strength = int.Parse(firstProperty); SecondLeg.Speed = int.Parse(secondProperty); } else if (energyConsumption < FirstLeg.EnergyConsumption) { FirstLeg.EnergyConsumption = energyConsumption; FirstLeg.Strength = int.Parse(firstProperty); FirstLeg.Speed = int.Parse(secondProperty); } else if (energyConsumption < SecondLeg.EnergyConsumption) { SecondLeg.EnergyConsumption = energyConsumption; SecondLeg.Strength = int.Parse(firstProperty); SecondLeg.Speed = int.Parse(secondProperty); } } else if (typeOfComponent == "Arm") { if (armsCount == 0) { armsCount = 1; FirstArm.EnergyConsumption = energyConsumption; FirstArm.ArmReachDistance = int.Parse(firstProperty); FirstArm.FingersCount = int.Parse(secondProperty); } else if (armsCount == 1) { armsCount = 2; SecondArm.EnergyConsumption = energyConsumption; SecondArm.ArmReachDistance = int.Parse(firstProperty); SecondArm.FingersCount = int.Parse(secondProperty); } else if (energyConsumption < FirstArm.EnergyConsumption) { FirstArm.EnergyConsumption = energyConsumption; FirstArm.ArmReachDistance = int.Parse(firstProperty); FirstArm.FingersCount = int.Parse(secondProperty); } else if (energyConsumption < SecondArm.EnergyConsumption) { SecondArm.EnergyConsumption = energyConsumption; SecondArm.ArmReachDistance = int.Parse(firstProperty); SecondArm.FingersCount = int.Parse(secondProperty); } } else if (typeOfComponent == "Head" && (headCounter == 0 || energyConsumption < Head.EnergyConsumption)) { headCounter = 1; Head.EnergyConsumption = energyConsumption; Head.IQ = int.Parse(firstProperty); Head.SkinMaterial = secondProperty; } else if (typeOfComponent == "Torso" && (torsoCounter == 0 || energyConsumption < Torso.EnergyConsumption)) { torsoCounter = 1; Torso.EnergyConsumption = energyConsumption; Torso.ProcessorSize = decimal.Parse(firstProperty); Torso.HousingMaterial = secondProperty; } data = Console.ReadLine(); } if (!(armsCount == 2 && legsCount == 2 && headCounter == 1 && torsoCounter == 1)) { Console.WriteLine("We need more parts!"); return; } var neededPower = Torso.EnergyConsumption + Head.EnergyConsumption + FirstArm.EnergyConsumption + SecondArm.EnergyConsumption + FirstLeg.EnergyConsumption + SecondLeg.EnergyConsumption; if (neededPower > maximumEnergyCapacity) { Console.WriteLine("We need more power!"); } else { PrintHead(Head); PrintTorso(Torso); if (FirstArm.EnergyConsumption <= SecondArm.EnergyConsumption) { PrintFirstArm(FirstArm); PrintSecondArm(SecondArm); } else { PrintSecondArm(SecondArm); PrintFirstArm(FirstArm); } if (FirstLeg.EnergyConsumption <= SecondLeg.EnergyConsumption) { PrintFirstLeg(FirstLeg); PrintSecondLeg(SecondLeg); } else { PrintSecondLeg(SecondLeg); PrintFirstLeg(FirstLeg); } } }
public bool Apply(Part p) { if (p == null) { return(false); } switch (p.GetType().Name) { case "Head": var h = (Head)p; if (head != null) { if (h.Energy >= head.Energy) { return(false); } energy -= head.Energy - h.Energy; head = h; } else { head = h; energy += h.Energy; } return(true); case "Torso": var t = (Torso)p; if (torso != null) { if (t.Energy >= torso.Energy) { return(false); } energy -= torso.Energy - t.Energy; torso = t; } else { torso = t; energy += t.Energy; } return(true); case "Arm": var a = (Arm)p; if (arms.Count > 1) { var idx = arms[0].Energy > arms[1].Energy ? 0 : 1; if (a.Energy >= arms[idx].Energy) { return(false); } energy -= arms[idx].Energy - a.Energy; arms.RemoveAt(idx); arms.Add(a); } else { arms.Add(a); energy += a.Energy; } return(true); case "Leg": var l = (Leg)p; if (legs.Count > 1) { var idx = legs[0].Energy > legs[1].Energy ? 0 : 1; if (l.Energy >= legs[idx].Energy) { return(false); } energy -= legs[idx].Energy - l.Energy; legs.RemoveAt(idx); legs.Add(l); } else { legs.Add(l); energy += l.Energy; } return(true); default: return(false); } }
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 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}"); } } }