Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace classes
- {
- class Truck
- {
- //Brand, Model and Weight.
- public string Brand { get; set; }
- public string Model { get; set; }
- public int Weight { get; set; }
- }
- class Car
- {
- //Brand, Model and Horse Power.
- public string Brand { get; set; }
- public string Model { get; set; }
- public int HorsePower { get; set; }
- }
- class Catalog
- {
- public List<Car> cars { get; set; }
- public List<Truck> trucks { get; set; }
- }
- class Program
- {
- static void Main(string[] args)
- {
- List<Car> cars = new List<Car>();
- List<Truck> trucks = new List<Truck>();
- string[] input = Console.ReadLine().Split("/").ToArray();
- while (input[0] != "end")
- {
- //{type}/{brand}/{model}/{horse power / weight}
- if (input[0] == "Car")
- {
- Car car = new Car();
- car.Brand = input[1];
- car.Model = input[2];
- car.HorsePower = int.Parse(input[3]);
- cars.Add(car);
- }
- else
- {
- Truck truck = new Truck();
- truck.Brand = input[1];
- truck.Model = input[2];
- truck.Weight = int.Parse(input[3]);
- trucks.Add(truck);
- }
- input = Console.ReadLine().Split("/").ToArray();
- }
- if (cars.Count > 0)
- {
- Console.WriteLine("Cars:");
- foreach (var item in cars.OrderBy(x => x.Brand))
- {
- Console.WriteLine($"{item.Brand}: {item.Model} - {item.HorsePower}hp");
- }
- }
- if (trucks.Count > 0)
- {
- Console.WriteLine("Trucks:");
- foreach (var item in trucks.OrderBy(x => x.Brand))
- {
- Console.WriteLine($"{item.Brand}: {item.Model} - {item.Weight}hp");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement