Advertisement
Guest User

Untitled

a guest
Jul 15th, 2017
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.55 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _03.Jarvis
  6. {
  7.     public class Robot
  8.     {
  9.         public List<Head> Heads { get; set; }
  10.         public List<Arms> Arms { get; set; }
  11.         public List<Legs> Legs { get; set; }
  12.         public List<Torso> Torsos { get; set; }
  13.     }
  14.     public class Head
  15.     {
  16.         public int EnergyConsumption { get; set; }
  17.         public int IQ { get; set; }
  18.         public string Material { get; set; }
  19.     }
  20.     public class Torso
  21.     {
  22.         public int EnergyConsumption { get; set; }
  23.         public decimal ProcessorSize { get; set; }
  24.         public string Material { get; set; }
  25.     }
  26.     public class Arms
  27.     {
  28.         public int EnergyConsumption { get; set; }
  29.         public int ArmsLenght { get; set; }
  30.         public int CountFingers { get; set; }
  31.     }
  32.     public class Legs
  33.     {
  34.         public int EnergyConsumption { get; set; }
  35.         public int Strenght { get; set; }
  36.         public int Speed { get; set; }
  37.     }
  38.  
  39.  
  40.     public class Program
  41.     {
  42.         public static void Main()
  43.         {
  44.             var totalEnergy = long.Parse(Console.ReadLine());
  45.             var robot = new Robot();
  46.             while (true)
  47.             {
  48.                 var line = Console.ReadLine().Split();
  49.                 if (line[0] == "Assemble!")
  50.                     break;
  51.                 var part = line[0];
  52.                 var currEnergyCons = int.Parse(line[1]);
  53.  
  54.                 if (part == "Head")
  55.                 {
  56.                     var currentHead = new Head();
  57.                     currentHead.EnergyConsumption = currEnergyCons;
  58.                     currentHead.IQ = int.Parse(line[2]);
  59.                     currentHead.Material = line[3];
  60.                     if (robot.Heads == null)
  61.                         robot.Heads = new List<Head>();
  62.                     robot.Heads.Add(currentHead);
  63.                 }
  64.                 else if (part == "Torso")
  65.                 {
  66.                     var currentTorso = new Torso();
  67.                     currentTorso.EnergyConsumption = currEnergyCons;
  68.                     currentTorso.ProcessorSize = decimal.Parse(line[2]);
  69.                     currentTorso.Material = line[3];
  70.                     if (robot.Torsos == null)
  71.                         robot.Torsos = new List<Torso>();
  72.                     robot.Torsos.Add(currentTorso);
  73.                 }
  74.                 else if (part == "Arm")
  75.                 {
  76.                     var currArm = new Arms();
  77.                     currArm.EnergyConsumption = currEnergyCons;
  78.                     currArm.ArmsLenght = int.Parse(line[2]);
  79.                     currArm.CountFingers = int.Parse(line[3]);
  80.                     if (robot.Arms == null)
  81.                         robot.Arms = new List<Arms>();
  82.                     robot.Arms.Add(currArm);
  83.                 }
  84.                 else if (part == "Leg")
  85.                 {
  86.                     var currLeg = new Legs();
  87.                     currLeg.EnergyConsumption = currEnergyCons;
  88.                     currLeg.Strenght = int.Parse(line[2]);
  89.                     currLeg.Speed = int.Parse(line[3]);
  90.                     if (robot.Legs == null)
  91.                         robot.Legs = new List<Legs>();
  92.                     robot.Legs.Add(currLeg);
  93.                 }
  94.             }
  95.             if (robot.Arms == null)
  96.                 robot.Arms = new List<Arms>();
  97.             if (robot.Legs == null)
  98.                 robot.Legs = new List<Legs>();
  99.             if (robot.Heads == null)
  100.                 robot.Heads = new List<Head>();
  101.             if (robot.Torsos == null)
  102.                 robot.Torsos = new List<Torso>();
  103.  
  104.             if (robot.Arms.Count > 1 && robot.Heads.Count > 0 &&
  105.                 robot.Legs.Count > 1 && robot.Torsos.Count > 0)
  106.             {
  107.                 long consumedEnergy =
  108.                       robot.Arms.OrderBy(x => x.EnergyConsumption).First().EnergyConsumption +
  109.                       robot.Arms.OrderBy(x => x.EnergyConsumption).Skip(1).Take(1).First().EnergyConsumption +
  110.                       robot.Legs.OrderBy(x => x.EnergyConsumption).First().EnergyConsumption +
  111.                       robot.Legs.OrderBy(x => x.EnergyConsumption).Skip(1).Take(1).First().EnergyConsumption +
  112.                       robot.Heads.OrderBy(x => x.EnergyConsumption).First().EnergyConsumption +
  113.                       robot.Torsos.OrderBy(x => x.EnergyConsumption).First().EnergyConsumption;
  114.                 if (consumedEnergy > totalEnergy)
  115.                     Console.WriteLine("We need more power!");
  116.                 else
  117.                 {
  118.                     Console.WriteLine("Jarvis:");
  119.                     foreach (var item in robot.Heads.OrderBy(x => x.EnergyConsumption).Take(1))
  120.                     {
  121.                         Console.WriteLine($"#Head:");
  122.                         Console.WriteLine($"###Energy consumption: {item.EnergyConsumption}");
  123.                         Console.WriteLine($"###IQ: {item.IQ}");
  124.                         Console.WriteLine($"###Skin material: {item.Material}");
  125.                     }
  126.                     foreach (var item in robot.Torsos.OrderBy(x => x.EnergyConsumption).Take(1))
  127.                     {
  128.                         Console.WriteLine($"#Torso:");
  129.                         Console.WriteLine($"###Energy consumption: {item.EnergyConsumption}");
  130.                         Console.WriteLine($"###Processor size: {item.ProcessorSize:f1}");
  131.                         Console.WriteLine($"###Corpus material: {item.Material}");
  132.                     }
  133.                     foreach (var item in robot.Arms.OrderBy(x => x.EnergyConsumption)
  134.                         .Take(2))
  135.                     {
  136.                         Console.WriteLine($"#Arm:");
  137.                         Console.WriteLine($"###Energy consumption: {item.EnergyConsumption}");
  138.                         Console.WriteLine($"###Reach: {item.ArmsLenght}");
  139.                         Console.WriteLine($"###Fingers: {item.CountFingers}");
  140.                     }
  141.                     foreach (var item in robot.Legs.OrderBy(x => x.EnergyConsumption)
  142.                         .Take(2))
  143.                     {
  144.                         Console.WriteLine($"#Leg:");
  145.                         Console.WriteLine($"###Energy consumption: {item.EnergyConsumption}");
  146.                         Console.WriteLine($"###Strength: {item.Strenght}");
  147.                         Console.WriteLine($"###Speed: {item.Speed}");
  148.                     }
  149.                 }
  150.             }
  151.             else
  152.                 Console.WriteLine("We need more parts!");
  153.         }
  154.     }
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement