Ejemplo n.º 1
0
            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());
            }
Ejemplo n.º 2
0
            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());
                }
            }
Ejemplo n.º 3
0
        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;
            }
        }
Ejemplo n.º 4
0
 public void AddArm(Arms arm)
 {
     if (Arms == null)
     {
         Arms = new List <Arms>();
     }
     if (Arms.Count < 2)
     {
         Arms.Add(arm);
     }
     else
     {
         for (int i = 0; i < Arms.Count; i++)
         {
             if (Arms[i].ArmsEnergy > arm.ArmsEnergy)
             {
                 Arms.RemoveAt(i);
                 Arms.Add(arm);
             }
         }
     }
 }
        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);
            }
        }
        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!");
            }
        }
        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!");
            }
        }
Ejemplo n.º 8
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());
        }