Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Net;
- using System.Globalization;
- using Cataloga;
- namespace Cataloga
- {
- class Car
- {
- public string Brand { get; set; }
- public string Model { get; set; }
- public string Weight { get; set; }
- public Car(string brand, string model, string weight)
- {
- this.Brand = brand;
- this.Model = model;
- this.Weight = weight;
- }
- public override string ToString()
- {
- return $"{this.Brand}: {this.Model} - {this.Weight}hp";
- }
- }
- class Truck
- {
- public string Brand { get; set; }
- public string Model { get; set; }
- public string Weight { get; set; }
- public Truck(string brand, string model, string weight)
- {
- this.Brand = brand;
- this.Model = model;
- this.Weight = weight;
- }
- public override string ToString()
- {
- return $"{this.Brand}: {this.Model} - {this.Weight}kg";
- }
- }
- class MainClass
- {
- public static void Main(string[] args)
- {
- List<Car> cars = new List<Car>();
- List<Truck> trucks = new List<Truck>();
- string input;
- int sum = 0;
- int sum2 = 0;
- while ((input = Console.ReadLine()) != "end")
- {
- string[] data = input.Split("/");
- string type = data[0];
- if (type == "Car")
- {
- sum++;
- string brand = data[1];
- string model = data[2];
- string weight = data[3];
- Car newCar = new Car(brand, model, weight);
- cars.Add(newCar);
- }
- else
- {
- sum2++;
- string brand = data[1];
- string model = data[2];
- string weight = data[3];
- Truck newTruck = new Truck(brand, model, weight);
- trucks.Add(newTruck);
- }
- }
- cars = cars.OrderBy(x => x.Brand).ToList();
- trucks = trucks.OrderBy(y => y.Brand).ToList();
- if (sum != 0)
- {
- Console.WriteLine("Cars:");
- Console.WriteLine(string.Join(Environment.NewLine, cars));
- }
- if (sum2 != 0)
- {
- Console.WriteLine("Trucks:");
- Console.WriteLine(string.Join(Environment.NewLine, trucks));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement