Advertisement
Guest User

Untitled

a guest
Mar 5th, 2023
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.69 KB | Source Code | 0 0
  1. var cars = new List<Car>();
  2.  
  3. int n = int.Parse(Console.ReadLine());
  4.  
  5. for (int i = 0; i < n; i++)
  6. {
  7.     string[] cmd = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
  8.  
  9.     string model = cmd[0];
  10.     int engineSpeed = int.Parse(cmd[1]);
  11.     int enginePower = int.Parse(cmd[2]);
  12.     int cargoWeight = int.Parse(cmd[3]);
  13.     string cargoType = cmd[4];
  14.  
  15.     var engine = new Engine()
  16.     {
  17.             EngineSpeed = engineSpeed,
  18.             EnginePower = enginePower
  19.     };
  20.     var cargo = new Cargo()
  21.     {
  22.         CargoWeight = cargoWeight,
  23.         CargoType = cargoType
  24.     };
  25.  
  26.     var car = new Car(model, engine, cargo);
  27.  
  28.     cars.Add(car);
  29. }
  30.  
  31. string crgType = Console.ReadLine();
  32.  
  33. if(crgType == "fragile")
  34. {
  35.     foreach (var car in cars.Where(x => x.Cargo.CargoType == "fragile" &&
  36.                                         x.Cargo.CargoWeight < 1000))
  37.     {
  38.     Console.WriteLine($"{car.Model}");
  39.     }
  40.  
  41. }
  42. else if (crgType == "flamable")
  43. {
  44.     foreach (var car in cars.Where(x => x.Cargo.CargoType == "flamable" &&
  45.                                         x.Engine.EnginePower > 250))
  46.     {
  47.         Console.WriteLine($"{car.Model}");
  48.     }
  49. }
  50.  
  51. public class Car
  52. {
  53.     public Car(string Mdl, Engine engine, Cargo cargo)
  54.     {
  55.         Model = Mdl;
  56.         Engine = engine;
  57.         Cargo = cargo;
  58.     }
  59.  
  60.     public string Model { get; set; }
  61.  
  62.     public Engine Engine { get; set; }
  63.  
  64.     public Cargo Cargo { get; set; }
  65. }
  66.  
  67. public class Engine
  68. {
  69.     public int EngineSpeed { get; set; }
  70.  
  71.     public int EnginePower { get; set; }
  72. }
  73.  
  74. public class Cargo
  75. {
  76.     public int CargoWeight { get; set; }
  77.  
  78.     public string CargoType { get; set; }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement