Advertisement
Iskrenov84

Raw data

Mar 4th, 2022
734
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.70 KB | None | 0 0
  1. using System;
  2. using System.Numerics;
  3. using System.Linq;
  4. using System.Collections.Generic;
  5.  
  6. namespace M4.RawData
  7. {
  8.     public class Car
  9.     {
  10.         public Car(string model, Engine engine, Cargo cargo)
  11.         {
  12.             this.Model = model;
  13.             this.Engine = engine;
  14.             this.Cargo = cargo;
  15.  
  16.         }
  17.         public string Model { get; set; }
  18.         public Engine Engine { get; set; }
  19.         public Cargo Cargo { get; set; }
  20.     }
  21.     public class Engine
  22.     {
  23.         public Engine(int enginePower, int engineSpeed)
  24.         {
  25.             this.EngineSpeed = engineSpeed;
  26.             this.EnginePower = enginePower;
  27.         }
  28.         public int EngineSpeed { get; set; }
  29.         public int EnginePower { get; set; }
  30.     }
  31.     public class Cargo
  32.     {
  33.         public Cargo(int cargoWeight, string cargoType)
  34.         {
  35.             this.CargoWeight = cargoWeight;
  36.             this.CargoType = cargoType;
  37.         }
  38.         public int CargoWeight { get; set; }
  39.         public string CargoType { get; set; }
  40.     }
  41.     internal class Program
  42.     {
  43.         static void Main(string[] args)
  44.         {
  45.             int numberOfCars = int.Parse(Console.ReadLine());
  46.  
  47.             List<Car> carsList = new List<Car>();
  48.  
  49.             for (int i = 0; i < numberOfCars; i++)
  50.             {
  51.                 string[] carInfo = Console.ReadLine()
  52.                     .Split(' ',StringSplitOptions.RemoveEmptyEntries)
  53.                     .ToArray();
  54.                 string model = carInfo[0];
  55.                 int engineSpeed = int.Parse(carInfo[1]);
  56.                 int enginePower = int.Parse(carInfo[2]);
  57.                 int cargoWeight = int.Parse(carInfo[3]);
  58.                 string cargoType = carInfo[4];
  59.                 Car car = new Car(model, new Engine (engineSpeed, enginePower), new Cargo (cargoWeight, cargoType));
  60.                 carsList.Add(car);
  61.             }
  62.  
  63.             string command = Console.ReadLine();
  64.  
  65.             switch (command)
  66.             {
  67.                 case "fragile":
  68.                     carsList.Where(x => x.Cargo.CargoType == "fragile")
  69.                         .Where(x => x.Cargo.CargoWeight < 1000)
  70.                         .Select(x => x.Model)
  71.                         .ToList()
  72.                         .ForEach(c => Console.WriteLine(c));
  73.                     break;
  74.                 case "flamable":
  75.                     carsList.Where(x => x.Cargo.CargoType == "flamable")
  76.                         .Where (x => x.Engine.EnginePower > 250)
  77.                         .Select (x => x.Model)
  78.                         .ToList()
  79.                         .ForEach(g => Console.WriteLine(g));
  80.                     break;
  81.             }
  82.         }
  83.     }
  84. }
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement