Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace Vehicle_Catalogue
- {
- class Program
- {
- class Catalog
- {
- public Catalog()
- {
- Cars = new List<Car>();
- Trucks = new List<Truck>();
- }
- public List<Car> Cars { get; set; }
- public List<Truck> Trucks { get; set; }
- }
- class Car
- {
- public string Brand { get; set; }
- public string Model { get; set; }
- public string HorsePower { get; set; }
- }
- class Truck
- {
- public string Brand { get; set; }
- public string Model { get; set; }
- public string weight { get; set; }
- }
- static void Main(string[] args)
- {
- Catalog catalog = new Catalog();
- while (true)
- {
- string[] command = Console.ReadLine()
- .Split('/');
- if (command[0] == "end")
- {
- break;
- }
- string type = command[0];
- string brand = command[1];
- string model = command[2];
- string horsePowerOrWeight =command[3];
- switch (type)
- {
- case "Truck":
- Truck currentTruck = new Truck();
- currentTruck.Brand = brand;
- currentTruck.Model = model;
- currentTruck.weight = horsePowerOrWeight;
- catalog.Trucks.Add(currentTruck);
- break;
- case "Car":
- Car currentCar = new Car();
- currentCar.Brand = brand;
- currentCar.Model = model;
- currentCar.HorsePower = horsePowerOrWeight;
- catalog.Cars.Add(currentCar);
- break;
- default:
- break;
- }
- }
- List<string> carBrands = new List<string>();
- List<Car> sortedCars = new List<Car>();
- for (int i = 0; i < catalog.Cars.Count; i++)
- {
- carBrands.Add(catalog.Cars[i].Brand);
- }
- carBrands.Sort();
- for (int i = 0; i < carBrands.Count; i++)
- {
- for (int j = 0; j < catalog.Cars.Count; j++)
- {
- if (catalog.Cars[j].Brand == carBrands[i])
- {
- sortedCars.Add(catalog.Cars[j]);
- }
- }
- }
- List<string> trucksBrands = new List<string>();
- List<Truck> sortedTrucks = new List<Truck>();
- for (int i = 0; i < catalog.Trucks.Count; i++)
- {
- trucksBrands.Add(catalog.Trucks[i].Brand);
- }
- trucksBrands.Sort();
- for (int i = 0; i < trucksBrands.Count; i++)
- {
- for (int j = 0; j < catalog.Trucks.Count; j++)
- {
- if (catalog.Trucks[j].Brand == trucksBrands[i])
- {
- sortedTrucks.Add(catalog.Trucks[j]);
- }
- }
- }
- if (sortedCars.Count > 0)
- {
- Console.WriteLine("Cars:");
- foreach (Car current in sortedCars)
- {
- Console.WriteLine($"{current.Brand}: {current.Model} - {current.HorsePower}hp");
- }
- }
- if (sortedTrucks.Count > 0)
- {
- Console.WriteLine("Trucks:");
- foreach (Truck current in sortedTrucks)
- {
- Console.WriteLine($"{current.Brand}: {current.Model} - {current.weight}kg");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement