예제 #1
0
        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);
            }
        }
        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!");
            }
        }
예제 #3
0
        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);
            }
        }
예제 #4
0
        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;
            }
        }
예제 #5
0
        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());
        }
예제 #6
0
        public static void Main()
        {
            long  maximumEnergy = long.Parse(Console.ReadLine());
            Robot robot         = new Robot();

            while (true)
            {
                string[] tokens = Console.ReadLine().Split();
                if (tokens[0] == "Assemble!")
                {
                    break;
                }

                var part           = tokens[0];
                var currEnergyCons = int.Parse(tokens[1]);

                if (part == "Head")
                {
                    Head currentHead = new Head();
                    currentHead.EnergyConsumption = currEnergyCons;
                    currentHead.IQ       = int.Parse(tokens[2]);
                    currentHead.Material = tokens[3];

                    if (robot.Heads == null)
                    {
                        robot.Heads = new List <Head>();
                    }
                    robot.Heads.Add(currentHead);
                }
                else if (part == "Torso")
                {
                    Torso currentTorso = new Torso();
                    currentTorso.EnergyConsumption = currEnergyCons;
                    currentTorso.ProcessorSize     = decimal.Parse(tokens[2]);
                    currentTorso.Material          = tokens[3];

                    if (robot.Torsos == null)
                    {
                        robot.Torsos = new List <Torso>();
                    }
                    robot.Torsos.Add(currentTorso);
                }
                else if (part == "Leg")
                {
                    var currLeg = new Legs();
                    currLeg.EnergyConsumption = currEnergyCons;
                    currLeg.Strenght          = int.Parse(tokens[2]);
                    currLeg.Speed             = int.Parse(tokens[3]);
                    if (robot.Legs == null)
                    {
                        robot.Legs = new List <Legs>();
                    }
                    robot.Legs.Add(currLeg);
                }
                else if (part == "Arm")
                {
                    var currArm = new Arms();
                    currArm.EnergyConsumption = currEnergyCons;
                    currArm.ArmsLenght        = int.Parse(tokens[2]);
                    currArm.CountFingers      = int.Parse(tokens[3]);
                    if (robot.Arms == null)
                    {
                        robot.Arms = new List <Arms>();
                    }
                    robot.Arms.Add(currArm);
                }
            }
            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 > maximumEnergy)
                {
                    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!");
            }
        }
예제 #7
0
        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;
            }
        }
예제 #8
0
      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}");
              }
          }
      }