Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace CarSalesman
- {
- public class Program
- {
- public static void Main(string[] args)
- {
- List<Engine> engines = new List<Engine>();
- int numberOfEngines = int.Parse(Console.ReadLine());
- for (int i = 0; i < numberOfEngines; i++)
- {
- string[] commandInfo = Console.ReadLine()
- .Split()
- .ToArray();
- string model = commandInfo[0];
- int power = int.Parse(commandInfo[1]);
- if(commandInfo.Length == 2)
- {
- Engine currentEngine = new Engine(model, power);
- engines.Add(currentEngine);
- }
- if(commandInfo.Length==3)
- {
- if(char.IsDigit(commandInfo[2][0]))
- {
- int displacement = int.Parse(commandInfo[2]);
- Engine currentEngine = new Engine(model, power, displacement);
- engines.Add(currentEngine);
- }
- else
- {
- string efficiency = commandInfo[2];
- Engine currentEngine = new Engine(model, power, efficiency);
- engines.Add(currentEngine);
- }
- }
- if(commandInfo.Length>3)
- {
- int displacement = int.Parse(commandInfo[2]);
- string efficiency = commandInfo[3];
- Engine currentEngine = new Engine(model, power, displacement,efficiency);
- engines.Add(currentEngine);
- }
- }
- List<Car> cars = new List<Car>();
- int numberOfCars = int.Parse(Console.ReadLine());
- for (int i = 0; i < numberOfCars; i++)
- {
- string[] commandInfo = Console.ReadLine()
- .Split()
- .ToArray();
- string model = commandInfo[0];
- string engineModel = commandInfo[1];
- Engine currentEngine = engines.FirstOrDefault(x => x.Model == engineModel);
- if (commandInfo.Length == 2)
- {
- Car currentCar = new Car(model, currentEngine);
- cars.Add(currentCar);
- }
- if (commandInfo.Length ==3)
- {
- if(char.IsDigit(commandInfo[2][0]))
- {
- int weight = int.Parse(commandInfo[2]);
- Car currentCar = new Car(model, currentEngine, weight);
- cars.Add(currentCar);
- }
- else
- {
- string color = commandInfo[2];
- Car currentCar = new Car(model, currentEngine, color);
- cars.Add(currentCar);
- }
- }
- if (commandInfo.Length > 3)
- {
- string color = commandInfo[3];
- int weight = int.Parse(commandInfo[2]);
- Car currentCar = new Car(model, currentEngine, weight,color);
- cars.Add(currentCar);
- }
- }
- foreach (var car in cars)
- {
- Console.WriteLine(car.Model+":");
- Console.WriteLine($" {car.Engine.Model}:");
- Console.WriteLine($" Power: {car.Engine.Power}");
- if(car.Engine.Displacement!=0)
- {
- Console.WriteLine($" Displacement: {car.Engine.Displacement}");
- }
- else
- {
- Console.WriteLine(" Displacement: n/a");
- }
- if(car.Engine.Efficiency!=null)
- {
- Console.WriteLine($" Efficiency: {car.Engine.Efficiency}");
- }
- else
- {
- Console.WriteLine(" Efficiency: n/a");
- }
- if(car.Weight!=0)
- {
- Console.WriteLine($" Weight: {car.Weight}");
- }
- else
- {
- Console.WriteLine(" Weight: n/a");
- }
- if (car.Color != null)
- {
- Console.WriteLine($" Color: {car.Color}");
- }
- else
- {
- Console.WriteLine(" Color: n/a");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement