Beispiel #1
0
        static void Main(string[] args)
        {
            List <Car> set   = new List <Car>();
            int        count = int.Parse(Console.ReadLine());

            for (int i = 0; i < count; i++)
            {
                List <string> tokens = Console.ReadLine()
                                       .Split()
                                       .ToList();
                string model = tokens[0];
                if (!set.Any(x => x.Model == model))
                {
                    tokens.RemoveAt(0);
                    List <double> tokensSec = tokens.Select(double.Parse).ToList();
                    Car           car       = new Car(model, tokensSec[0], tokensSec[1]);
                    set.Add(car);
                }
            }

            string command = Console.ReadLine();

            while (command != "End")
            {
                string[] tokens     = command.Split();
                string   model      = tokens[1];
                int      amountKm   = int.Parse(tokens[2]);
                Car      currentCar = set.First(x => x.Model == model);
                currentCar.MoveCar(amountKm);
                command = Console.ReadLine();
            }
            Console.WriteLine(string.Join(Environment.NewLine, set));
        }
Beispiel #2
0
        public static void Main()
        {
            int        n    = int.Parse(Console.ReadLine());
            List <Car> cars = new List <Car>();

            for (int i = 0; i < n; i++)
            {
                string[] carInfo = Console.ReadLine().Split(" ");

                string model      = carInfo[0];
                double fuelAmount = double.Parse(carInfo[1]);
                double fuelConsumptionPerKilometer = double.Parse(carInfo[2]);


                Car currCar = new Car(model, fuelAmount, fuelConsumptionPerKilometer);
                cars.Add(currCar);
            }

            string command = Console.ReadLine();

            while (command != "End")
            {
                string[] tokens             = command.Split(" ");
                string   carModel           = tokens[1];
                double   amountOfKilometers = double.Parse(tokens[2]);

                Car  car      = cars.FirstOrDefault(c => c.Model == carModel);
                bool isDriven = car.MoveCar(amountOfKilometers);

                if (!isDriven)
                {
                    Console.WriteLine("Insufficient fuel for the drive");
                }

                command = Console.ReadLine();
            }

            foreach (Car car in cars)
            {
                Console.WriteLine($"{car.Model} {car.FuelAmount:f2} {car.TravelledDistance}");
            }
        }