Exemplo n.º 1
0
        static void Main()
        {
            BigInteger maxEnergyConsumption = BigInteger.Parse(Console.ReadLine());

            Jarvis jarvis = AssembleJarvis();
            var    totalJarvisPartsEnergyConsumption = 0;

            for (int i = 0; i < 2; i++)
            {
                totalJarvisPartsEnergyConsumption += jarvis.Arms[i].EnergyConsumption;
                totalJarvisPartsEnergyConsumption += jarvis.Legs[i].EnergyConsumption;
            }

            totalJarvisPartsEnergyConsumption += jarvis.Head.EnergyConsumption + jarvis.Torso.EnergyConsumption;

            if (maxEnergyConsumption < totalJarvisPartsEnergyConsumption)
            {
                Console.WriteLine("We need more power!");
            }
            else if (jarvis.Head.EnergyConsumption == 0 || jarvis.Torso.EnergyConsumption == 0 ||
                     jarvis.Arms.Count <= 0 || jarvis.Legs.Count <= 0)
            {
                Console.WriteLine("We need more parts!");
            }
            else
            {
                PrintJarvis(jarvis);
            }
        }
Exemplo n.º 2
0
        private void BtnStart_Click(object sender, EventArgs e)
        {
            Jarvis.ConvexHull(Jarvis.Points);
            List <Point> JRpoints = new List <Point>();

            foreach (Point point in Jarvis.ConvexHull(Jarvis.Points))
            {
                Engine.g.FillEllipse(Brushes.Red, point.X - 3, point.Y - 3, 6, 6);
                JRpoints.Add(point);
            }

            for (int i = 0; i < JRpoints.Count; i++)
            {
                if (JRpoints[JRpoints.Count - 1] == JRpoints[i])
                {
                    Engine.g.DrawLine(Pens.Black, JRpoints[JRpoints.Count - 1], JRpoints[0]);
                }
                else
                {
                    Engine.g.DrawLine(Pens.Black, JRpoints[i], JRpoints[i + 1]);
                }
            }

            pictureBox1.Image = Engine.b;
        }
        static void ReadJarvisComponents(Jarvis jarvis)
        {
            var component = Console.ReadLine().Split();

            while (component[0] != "Assemble!")
            {
                var compName  = component[0];
                var compSpecs = component.Skip(1).ToList();

                switch (compName)
                {
                case "Head":
                    ReadHead(compSpecs, jarvis);
                    break;

                case "Torso":
                    ReadTorso(compSpecs, jarvis);
                    break;

                case "Arm":
                    ReadArm(compSpecs, jarvis);
                    break;

                case "Leg":
                    ReadLeg(compSpecs, jarvis);
                    break;
                }

                component = Console.ReadLine().Split();
            }
        }
        static void PrintComponents(Jarvis jarvis)
        {
            Console.WriteLine("Jarvis:");

            Console.WriteLine("#Head:");
            Console.WriteLine($"###Energy consumption: {jarvis.Head.EnergyConsumption}");
            Console.WriteLine($"###IQ: {jarvis.Head.IQ}");
            Console.WriteLine($"###Skin material: {jarvis.Head.SkinMaterial}");

            Console.WriteLine("#Torso:");
            Console.WriteLine($"###Energy consumption: {jarvis.Torso.EnergyConsumption}");
            Console.WriteLine($"###Processor size: {jarvis.Torso.Processor.ToString("0.0")}");
            Console.WriteLine($"###Corpus material: {jarvis.Torso.HousingMaterial}");

            foreach (var arm in jarvis.Arms.OrderBy(a => a.EnergyConsumption))
            {
                Console.WriteLine("#Arm:");
                Console.WriteLine($"###Energy consumption: {arm.EnergyConsumption}");
                Console.WriteLine($"###Reach: {arm.Reach}");
                Console.WriteLine($"###Fingers: {arm.Fingers}");
            }

            foreach (var leg in jarvis.Legs.OrderBy(l => l.EnergyConsumption))
            {
                Console.WriteLine("#Leg:");
                Console.WriteLine($"###Energy consumption: {leg.EnergyConsumption}");
                Console.WriteLine($"###Strength: {leg.Strength}");
                Console.WriteLine($"###Speed: {leg.Speed}");
            }
        }
        static void ReadHead(List <string> compSpecs, Jarvis jarvis)
        {
            Head head = new Head
            {
                EnergyConsumption = long.Parse(compSpecs[0]),
                IQ           = long.Parse(compSpecs[1]),
                SkinMaterial = compSpecs[2]
            };

            if (jarvis.Head == null)
            {
                jarvis.Head = head;
            }
            else if (jarvis.Head.EnergyConsumption > head.EnergyConsumption)
            {
                jarvis.Head = head;
            }
        }
        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;
            }
        }
        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();
            }
        }
        static void ReadLeg(List <string> compSpecs, Jarvis jarvis)
        {
            Leg leg = new Leg
            {
                EnergyConsumption = long.Parse(compSpecs[0]),
                Strength          = long.Parse(compSpecs[1]),
                Speed             = long.Parse(compSpecs[2])
            };

            jarvis.Legs.Add(leg);

            jarvis.Legs = jarvis.Legs.OrderBy(l => l.EnergyConsumption).ToList();

            if (jarvis.Legs.Count > 2)
            {
                jarvis.Legs = jarvis.Legs.Take(2).ToList();
            }
        }
        static void Main(string[] args)
        {
            var capacity = long.Parse(Console.ReadLine());

            Jarvis jarvis = new Jarvis();

            ReadJarvisComponents(jarvis);

            long totalEnergy = 0;

            if (jarvis.Head != null)
            {
                totalEnergy += jarvis.Head.EnergyConsumption;
            }

            if (jarvis.Torso != null)
            {
                totalEnergy += jarvis.Torso.EnergyConsumption;
            }

            foreach (var arm in jarvis.Arms)
            {
                totalEnergy += arm.EnergyConsumption;
            }

            foreach (var leg in jarvis.Legs)
            {
                totalEnergy += leg.EnergyConsumption;
            }

            if (totalEnergy > capacity)
            {
                Console.WriteLine("We need more power!");
                return;
            }

            if (jarvis.Head == null || jarvis.Torso == null || jarvis.Arms.Count != 2 || jarvis.Legs.Count != 2)
            {
                Console.WriteLine("We need more parts!");
                return;
            }

            PrintComponents(jarvis);
        }
Exemplo n.º 10
0
        private static void PrintJarvis(Jarvis jarvis)
        {
            Console.WriteLine("Jarvis:");

            Console.WriteLine($"#Head:\r\n###Energy consumption: {jarvis.Head.EnergyConsumption}");
            Console.WriteLine($"###IQ: {jarvis.Head.IQ}\r\n###Skin material: {jarvis.Head.SkinMaterial}");
            Console.WriteLine($"#Torso:\r\n###Energy consumption: {jarvis.Torso.EnergyConsumption}");
            Console.WriteLine($"###Processor size: {jarvis.Torso.ProcessorSize:f1}\r\n###Corpus material: {jarvis.Torso.HousingMaterial}");

            foreach (var arm in jarvis.Arms.OrderBy(x => x.EnergyConsumption))
            {
                Console.WriteLine($"#Arm:\r\n###Energy consumption: {arm.EnergyConsumption}");
                Console.WriteLine($"###Reach: {arm.ReachDistance}\r\n###Fingers: {arm.FingerCount}");
            }

            foreach (var leg in jarvis.Legs.OrderBy(x => x.EnergyConsumption))
            {
                Console.WriteLine($"#Leg:\r\n###Energy consumption: {leg.EnergyConsumption}");
                Console.WriteLine($"###Strength: {leg.Strength}\r\n###Speed: {leg.Speed}");
            }
        }
Exemplo n.º 11
0
 public static void Main(string[] args)
 {
     Jarvis jarvis = new Jarvis();
 }
Exemplo n.º 12
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());
        }
Exemplo n.º 13
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);
        }