Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Numerics;
- using System.Linq;
- using System.Collections.Generic;
- namespace M4.RawData
- {
- public class Car
- {
- public Car(string model, Engine engine, Cargo cargo)
- {
- this.Model = model;
- this.Engine = engine;
- this.Cargo = cargo;
- }
- public string Model { get; set; }
- public Engine Engine { get; set; }
- public Cargo Cargo { get; set; }
- }
- public class Engine
- {
- public Engine(int enginePower, int engineSpeed)
- {
- this.EngineSpeed = engineSpeed;
- this.EnginePower = enginePower;
- }
- public int EngineSpeed { get; set; }
- public int EnginePower { get; set; }
- }
- public class Cargo
- {
- public Cargo(int cargoWeight, string cargoType)
- {
- this.CargoWeight = cargoWeight;
- this.CargoType = cargoType;
- }
- public int CargoWeight { get; set; }
- public string CargoType { get; set; }
- }
- internal class Program
- {
- static void Main(string[] args)
- {
- int numberOfCars = int.Parse(Console.ReadLine());
- List<Car> carsList = new List<Car>();
- for (int i = 0; i < numberOfCars; i++)
- {
- string[] carInfo = Console.ReadLine()
- .Split(' ',StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- string model = carInfo[0];
- int engineSpeed = int.Parse(carInfo[1]);
- int enginePower = int.Parse(carInfo[2]);
- int cargoWeight = int.Parse(carInfo[3]);
- string cargoType = carInfo[4];
- Car car = new Car(model, new Engine (engineSpeed, enginePower), new Cargo (cargoWeight, cargoType));
- carsList.Add(car);
- }
- string command = Console.ReadLine();
- switch (command)
- {
- case "fragile":
- carsList.Where(x => x.Cargo.CargoType == "fragile")
- .Where(x => x.Cargo.CargoWeight < 1000)
- .Select(x => x.Model)
- .ToList()
- .ForEach(c => Console.WriteLine(c));
- break;
- case "flamable":
- carsList.Where(x => x.Cargo.CargoType == "flamable")
- .Where (x => x.Engine.EnginePower > 250)
- .Select (x => x.Model)
- .ToList()
- .ForEach(g => Console.WriteLine(g));
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement