private static Arm ReadArm(string input) { string[] elements = input.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries); Arm arm = new Arm { EnergyConsumption = int.Parse(elements[1]), ReachDistance = int.Parse(elements[2]), CountOfFingers = int.Parse(elements[3]) }; return(arm); }
private static void SelectArmByMinEnergyConsumption(Arm newArm, List <Arm> arms) { if (arms.Count < 2) { arms.Add(newArm); } else { for (int i = 0; i < arms.Count; i++) { if (newArm.EnergyConsumption < arms[i].EnergyConsumption) { arms[i] = newArm; break; } } } }
static void ReadArm(List <string> compSpecs, Jarvis jarvis) { Arm arm = new Arm { EnergyConsumption = long.Parse(compSpecs[0]), Reach = long.Parse(compSpecs[1]), Fingers = long.Parse(compSpecs[2]) }; jarvis.Arms.Add(arm); jarvis.Arms = jarvis.Arms.OrderBy(a => a.EnergyConsumption).ToList(); if (jarvis.Arms.Count > 2) { jarvis.Arms = jarvis.Arms.Take(2).ToList(); } }
public void AddArm(Arm armInput) { if (Arms == null) { Arms = new List <Arm>(); } if (Arms.Count < 2) { Arms.Add(armInput); } else { for (int i = 0; i < Arms.Count; i++) { if (armInput.EnergyCons < Arms[i].EnergyCons) { Arms.RemoveAt(i); Arms.Add(armInput); } } } }
public void AddArm(Arm armInput) { //проверяваме дали ни е създадена истанция от листовете if (Arms == null) { Arms = new List <Arm>(); } if (Arms.Count < 2) { Arms.Add(armInput); } else { for (int i = 0; i < this.Arms.Count; i++) { if (Arms[i].Energy > armInput.Energy) { Arms.RemoveAt(i); Arms.Add(armInput); } } } }
static void Main(string[] args) { long jarvisEnergy = long.Parse(Console.ReadLine()); Jarvis jarvis = new Jarvis() { Energy = jarvisEnergy }; while (true) { var input = Console.ReadLine().Split(' '); if (input[0] == "Assemble!") { break; } switch (input[0]) { case "Head": Head head = new Head() { EnergyCons = int.Parse(input[1]), IQ = int.Parse(input[2]), Material = input[3] }; jarvis.AddHead(head); break; case "Torso": Torso torso = new Torso() { EnergyCons = int.Parse(input[1]), ProcessorSize = double.Parse(input[2]), Material = input[3] }; jarvis.AddTorso(torso); break; case "Arm": Arm arm = new Arm() { EnergyCons = int.Parse(input[1]), Reach = int.Parse(input[2]), FingerCount = int.Parse(input[3]) }; jarvis.AddArm(arm); break; case "Leg": Leg leg = new Leg() { EnergyCons = int.Parse(input[1]), Strength = int.Parse(input[2]), Speed = int.Parse(input[3]) }; jarvis.AddLeg(leg); break; } } Console.WriteLine(jarvis.ToString()); }
static Jarvis AssembleJarvis() { var input = Console.ReadLine(); Jarvis jarvis = new Jarvis(); jarvis.Arms = new List <Arm>(); jarvis.Legs = new List <Leg>(); jarvis.Head = new Head(); jarvis.Torso = new Torso(); while (input != "Assemble!") { var robotTokens = input.Split(' ').ToArray(); var componentType = robotTokens[0]; var energyConsumption = int.Parse(robotTokens[1]); var firstProperty = robotTokens[2]; var secondProperty = robotTokens[3]; switch (componentType) { case "Arm": Arm arm = new Arm(); arm.EnergyConsumption = energyConsumption; arm.ReachDistance = int.Parse(firstProperty); arm.FingerCount = int.Parse(secondProperty); if (jarvis.Arms.Count == 2) { if (jarvis.Arms[0].EnergyConsumption > arm.EnergyConsumption && jarvis.Arms[1].EnergyConsumption > arm.EnergyConsumption) { jarvis.Arms.Remove(jarvis.Arms[0]); jarvis.Arms.Add(arm); } else { foreach (var jarvisArm in jarvis.Arms) { if (arm.EnergyConsumption < jarvisArm.EnergyConsumption) { jarvis.Arms.Remove(jarvisArm); jarvis.Arms.Add(arm); break; } } } } else { jarvis.Arms.Add(arm); } break; case "Leg": Leg leg = new Leg(); leg.EnergyConsumption = energyConsumption; leg.Strength = int.Parse(firstProperty); leg.Speed = int.Parse(secondProperty); if (jarvis.Legs.Count == 2) { if (jarvis.Legs[0].EnergyConsumption > leg.EnergyConsumption && jarvis.Legs[1].EnergyConsumption > leg.EnergyConsumption) { jarvis.Legs.Remove(jarvis.Legs[0]); jarvis.Legs.Add(leg); } else { foreach (var jarvisLeg in jarvis.Legs) { if (leg.EnergyConsumption < jarvisLeg.EnergyConsumption) { jarvis.Legs.Remove(jarvisLeg); jarvis.Legs.Add(leg); break; } } } } else { jarvis.Legs.Add(leg); } break; case "Head": if (jarvis.Head.EnergyConsumption != 0) { if (jarvis.Head.EnergyConsumption > energyConsumption) { jarvis.Head.EnergyConsumption = energyConsumption; jarvis.Head.IQ = int.Parse(firstProperty); jarvis.Head.SkinMaterial = secondProperty; } break; } else { jarvis.Head.EnergyConsumption = energyConsumption; jarvis.Head.IQ = int.Parse(firstProperty); jarvis.Head.SkinMaterial = secondProperty; } break; case "Torso": Torso torso = new Torso(); torso.EnergyConsumption = energyConsumption; torso.ProcessorSize = double.Parse(firstProperty); torso.HousingMaterial = secondProperty; jarvis.Torso = torso; if (jarvis.Torso.EnergyConsumption > torso.EnergyConsumption) { jarvis.Torso = torso; } break; } input = Console.ReadLine(); } return(jarvis); }
static void Main(string[] args) { long maxEnergy = long.Parse(Console.ReadLine()); Robot robot = new Robot(); robot.Energy = maxEnergy; while (true) { string[] tokens = Console.ReadLine() .Split(); if (tokens[0] == "Assemble!") { break; } switch (tokens[0]) { case "Head": Head newHead = new Head ( int.Parse(tokens[1]), int.Parse(tokens[2]), tokens[3] ); robot.AddHead(newHead); break; case "Torso": Torso newTorso = new Torso ( int.Parse(tokens[1]), double.Parse(tokens[2]), tokens[3] ); robot.AddTorso(newTorso); break; case "Arm": Arm newArm = new Arm ( int.Parse(tokens[1]), int.Parse(tokens[2]), int.Parse(tokens[3]) ); robot.AddArm(newArm); break; case "Leg": Leg newLeg = new Leg ( int.Parse(tokens[1]), int.Parse(tokens[2]), int.Parse(tokens[3]) ); robot.AddLeg(newLeg); break; } } Console.WriteLine(robot.ToString()); }