public static void Main(string[] args) { HashSet <Car> carSet = new HashSet <Car>(); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] info = Console .ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries) .ToArray(); string model = info[0]; double amount = double.Parse(info[1]); double fuelConsumtion = double.Parse(info[2]); Car car = new Car(model, amount, fuelConsumtion); carSet.Add(car); } string input; while ((input = Console.ReadLine()) != "End") { string[] info = input.Split(" ", StringSplitOptions.RemoveEmptyEntries); string model = info[1]; double distance = double.Parse(info[2]); if (carSet.Any(x => x.Model == model)) { Car selectedCar = carSet.Where(x => x.Model == model).FirstOrDefault(); double neededFuel = distance * selectedCar.FuelConsumptionPerKilometer; if (selectedCar.FuelAmount >= neededFuel) { selectedCar.FuelAmount -= neededFuel; selectedCar.TravelledDistance += distance; } else { Console.WriteLine("Insufficient fuel for the drive"); } } } foreach (var car in carSet) { car.PrintCar(); } }
public static void Main(string[] args) { Car car = new Car(); var engines = new List <Engine>(); var cars = new List <Car>(); int numberN = int.Parse(Console.ReadLine()); for (int i = 0; i < numberN; i++) { Engine engine = new Engine(); var inputEngine = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).ToList(); if (inputEngine.Count() == 2) { two(inputEngine, engine, engines); } else if (inputEngine.Count() == 3) { three(inputEngine, engine, engines); } else if (inputEngine.Count() == 4) { four(inputEngine, engine, engines); } } int numberM = int.Parse(Console.ReadLine()); for (int i = 0; i < numberM; i++) { car = new Car(); var inputCar = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries).ToList(); string model = inputCar[0]; car.Model = model; string engine = inputCar[1]; for (int j = 0; j < engines.Count; j++) { if (engines[j].ModelEngine == (engine)) { car.Engine = engines[j]; } } if (inputCar.Count() == 3) { int weight = 0; bool bol = int.TryParse(inputCar[2], out weight); if (bol) { car.Weight = weight.ToString(); car.Color = "n/a"; } else { car.Weight = "n/a"; car.Color = inputCar[2]; } } else if (inputCar.Count() == 4) { car.Weight = inputCar[2]; car.Color = inputCar[3]; } else { car.Weight = "n/a"; car.Color = "n/a"; } cars.Add(car); } car.PrintCar(cars); }