Esempio n. 1
0
            public override string ToString()
            {
                if (Head == null || Torso == null || Arms.Count < 2 || Legs.Count < 2)
                {
                    return("We need more parts!");
                }
                long totalEnergy = 0;

                totalEnergy += Head.EnergyCons;
                totalEnergy += Torso.EnergyCons;
                totalEnergy += Arms.Select(x => long.Parse(x.EnergyCons.ToString())).Sum();
                totalEnergy += Legs.Select(x => long.Parse(x.EnergyCons.ToString())).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 (var arm in Arms.OrderBy(x => x.EnergyCons))
                {
                    sb.Append(arm.ToString());
                }
                foreach (var leg in Legs.OrderBy(x => x.EnergyCons))
                {
                    sb.Append(leg.ToString());
                }


                return(sb.ToString());
            }
Esempio n. 2
0
 private static void SelectTorsoByMinEnergyConsumption(Torso newTorso, Robot jarvis)
 {
     if ((jarvis.Torso.EnergyConsumption == 0) || (newTorso.EnergyConsumption < jarvis.Torso.EnergyConsumption))
     {
         jarvis.Torso = newTorso;
     }
 }
Esempio n. 3
0
        public void Assemble()
        {
            if (!HasEnoughPart())
            {
                Console.WriteLine("We need more parts!");
            }
            else if (!HasEnoughEnergy())
            {
                Console.WriteLine("We need more power!");
            }
            else
            {
                Console.WriteLine("Jarvis:");

                Head currentHead = head.OrderBy(x => x.EnergyConsumption).Take(1).First();
                Console.WriteLine(currentHead.ToString());

                Torso currentTorso = torso.OrderBy(x => x.EnergyConsumption).Take(1).First();
                Console.WriteLine(currentTorso.ToString());

                Arm[] armsArray = arms.OrderBy(x => x.EnergyConsumption).Take(2).ToArray();
                Console.WriteLine(armsArray[0].ToString());
                Console.WriteLine(armsArray[1].ToString());


                Leg[] legArray = legs.OrderBy(x => x.EnergyConsumption).Take(2).ToArray();
                Console.WriteLine(legArray[0].ToString());
                Console.WriteLine(legArray[1].ToString());
            }
        }
Esempio n. 4
0
 public void AddTorso(Torso torsoInput)
 {
     if (Torso == null)
     {
         Torso = torsoInput;
     }
     if (torsoInput.EnergyCons < Torso.EnergyCons)
     {
         Torso = torsoInput;
     }
 }
Esempio n. 5
0
        private static Torso ReadTorso(string input)
        {
            string[] elements = input.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);

            Torso torso = new Torso
            {
                EnergyConsumption          = int.Parse(elements[1]),
                ProcessorSizeInCentimeters = double.Parse(elements[2]),
                Material = elements[3]
            };

            return(torso);
        }
        static void ReadTorso(List <string> compSpecs, Jarvis jarvis)
        {
            Torso torso = new Torso
            {
                EnergyConsumption = long.Parse(compSpecs[0]),
                Processor         = double.Parse(compSpecs[1]),
                HousingMaterial   = compSpecs[2]
            };

            if (jarvis.Torso == null)
            {
                jarvis.Torso = torso;
            }
            else if (jarvis.Torso.EnergyConsumption > torso.EnergyConsumption)
            {
                jarvis.Torso = torso;
            }
        }
        public static void Main()
        {
            BigInteger maxEnergy = BigInteger.Parse(Console.ReadLine());

            string input = Console.ReadLine();

            Robot myRobot = new Robot();

            myRobot.Name = "Jarvis";
            myRobot.Arm  = new List <Arms> {
            };
            myRobot.Leg  = new List <Legs> {
            };
            myRobot.Body = new List <Torso> {
            };
            myRobot.Head = new List <Head> {
            };

            BigInteger currentEnergy = maxEnergy;

            while (input != "Assemble!")
            {
                string[] inputArray = input
                                      .Trim()
                                      .Split(new string[] { " " }, StringSplitOptions
                                             .RemoveEmptyEntries)
                                      .ToArray();

                string currentComponent = inputArray[0];

                switch (currentComponent)
                {
                case "Arm":

                    Arms currentArm = new Arms();

                    currentArm.Energy  = int.Parse(inputArray[1]);
                    currentArm.Reach   = int.Parse(inputArray[2]);
                    currentArm.Fingers = int.Parse(inputArray[3]);

                    if (myRobot.Arm.Count < 2)
                    {
                        currentEnergy -= currentArm.Energy;

                        myRobot.Arm.Add(currentArm);
                    }
                    else if (currentArm.Energy < Math.Min(myRobot.Arm[0].Energy, myRobot.Arm[1].Energy))
                    {
                        currentEnergy += (myRobot.Arm[0].Energy - currentArm.Energy);

                        myRobot.Arm[0] = currentArm;
                    }
                    else if (currentArm.Energy < myRobot.Arm[1].Energy)
                    {
                        currentEnergy += (myRobot.Arm[1].Energy - currentArm.Energy);

                        myRobot.Arm[1] = currentArm;
                    }
                    break;

                case "Leg":

                    Legs currentLeg = new Legs();

                    currentLeg.Energy   = int.Parse(inputArray[1]);
                    currentLeg.Strength = int.Parse(inputArray[2]);
                    currentLeg.Speed    = int.Parse(inputArray[3]);

                    if (myRobot.Leg.Count < 2)
                    {
                        currentEnergy -= currentLeg.Energy;

                        myRobot.Leg.Add(currentLeg);
                    }
                    else if (currentLeg.Energy < Math.Min(myRobot.Leg[0].Energy, myRobot.Leg[1].Energy))
                    {
                        currentEnergy += (myRobot.Leg[0].Energy - currentLeg.Energy);

                        myRobot.Leg[0] = currentLeg;
                    }
                    else if (currentLeg.Energy < myRobot.Leg[1].Energy)
                    {
                        currentEnergy += (myRobot.Leg[1].Energy - currentLeg.Energy);

                        myRobot.Leg[1] = currentLeg;
                    }
                    break;

                case "Torso":

                    Torso currentBody = new Torso();

                    currentBody.Energy        = int.Parse(inputArray[1]);
                    currentBody.ProcessorSize = double.Parse(inputArray[2]);
                    currentBody.Material      = inputArray[3];


                    if (myRobot.Body.Count < 1)
                    {
                        currentEnergy -= currentBody.Energy;

                        myRobot.Body.Add(currentBody);
                    }
                    else if (currentBody.Energy < myRobot.Body[0].Energy)
                    {
                        currentEnergy += (myRobot.Body[0].Energy - currentBody.Energy);

                        myRobot.Body[0] = currentBody;
                    }
                    break;

                case "Head":

                    Head currentHead = new Head();

                    currentHead.Energy   = int.Parse(inputArray[1]);
                    currentHead.IQ       = int.Parse(inputArray[2]);
                    currentHead.Material = inputArray[3];

                    if (myRobot.Head.Count < 1)
                    {
                        currentEnergy -= currentHead.Energy;

                        myRobot.Head.Add(currentHead);
                    }
                    else if (currentHead.Energy < myRobot.Head[0].Energy)
                    {
                        currentEnergy += (myRobot.Head[0].Energy - currentHead.Energy);

                        myRobot.Head[0] = currentHead;
                    }
                    break;
                }

                input = Console.ReadLine();
            }

            bool needParts = myRobot.Arm.Count < 2 ||
                             myRobot.Leg.Count < 2 ||
                             myRobot.Body.Count < 1 ||
                             myRobot.Head.Count < 1;

            if (currentEnergy < 0)
            {
                Console.WriteLine("We need more power!");
            }
            else if (needParts)
            {
                Console.WriteLine("We need more parts!");
            }
            else
            {
                Console.WriteLine($"{myRobot.Name}:");

                Console.WriteLine("#Head:");
                Console.WriteLine($"###Energy consumption: {myRobot.Head[0].Energy}");
                Console.WriteLine($"###IQ: {myRobot.Head[0].IQ}");
                Console.WriteLine($"###Skin material: {myRobot.Head[0].Material}");

                Console.WriteLine("#Torso:");
                Console.WriteLine($"###Energy consumption: {myRobot.Body[0].Energy}");
                Console.WriteLine($"###Processor size: {myRobot.Body[0].ProcessorSize:f1}");
                Console.WriteLine($"###Corpus material: {myRobot.Body[0].Material}");

                int armFirstIndex = myRobot.Arm.IndexOf(myRobot.Arm.OrderBy(e => e.Energy).FirstOrDefault());

                int legFirstIndex = myRobot.Leg.IndexOf(myRobot.Leg.OrderBy(e => e.Energy).FirstOrDefault());

                Console.WriteLine("#Arm:");
                Console.WriteLine($"###Energy consumption: {myRobot.Arm[armFirstIndex].Energy}");
                Console.WriteLine($"###Reach: {myRobot.Arm[armFirstIndex].Reach}");
                Console.WriteLine($"###Fingers: {myRobot.Arm[armFirstIndex].Fingers}");

                Console.WriteLine("#Arm:");
                Console.WriteLine($"###Energy consumption: {myRobot.Arm[1 - armFirstIndex].Energy}");
                Console.WriteLine($"###Reach: {myRobot.Arm[1 - armFirstIndex].Reach}");
                Console.WriteLine($"###Fingers: {myRobot.Arm[1 - armFirstIndex].Fingers}");

                Console.WriteLine("#Leg:");
                Console.WriteLine($"###Energy consumption: {myRobot.Leg[legFirstIndex].Energy}");
                Console.WriteLine($"###Strength: {myRobot.Leg[legFirstIndex].Strength}");
                Console.WriteLine($"###Speed: {myRobot.Leg[legFirstIndex].Speed}");

                Console.WriteLine("#Leg:");
                Console.WriteLine($"###Energy consumption: {myRobot.Leg[1 - legFirstIndex].Energy}");
                Console.WriteLine($"###Strength: {myRobot.Leg[1 - legFirstIndex].Strength}");
                Console.WriteLine($"###Speed: {myRobot.Leg[1 - legFirstIndex].Speed}");
            }
        }
Esempio n. 8
0
        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());
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        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());
        }