コード例 #1
0
        public static void Main()
        {
            int        n    = int.Parse(Console.ReadLine());
            List <Car> cars = new List <Car>();

            for (int i = 0; i < n; i++)
            {
                Queue <string> carInfo = new Queue <string>(Console.ReadLine()
                                                            .Split(" ", StringSplitOptions.RemoveEmptyEntries));

                string model       = carInfo.Dequeue();
                int    engineSpeed = int.Parse(carInfo.Dequeue());
                int    enginePower = int.Parse(carInfo.Dequeue());
                int    cargoWeight = int.Parse(carInfo.Dequeue());
                string cargoType   = carInfo.Dequeue();

                Engine      engine = new Engine(engineSpeed, enginePower);
                Cargo       cargo  = new Cargo(cargoWeight, cargoType);
                List <Tire> tires  = new List <Tire>();

                while (carInfo.Any())
                {
                    double tirePressure = double.Parse(carInfo.Dequeue());
                    int    tireYear     = int.Parse(carInfo.Dequeue());
                    Tire   tire         = new Tire(tirePressure, tireYear);
                    tires.Add(tire);
                }

                Car car = new Car(model, engine, cargo, tires);
                cars.Add(car);
            }

            string command = Console.ReadLine();

            if (command == "fragile")
            {
                foreach (var car in cars.Where(x => x.Cargo.CargoType == command && x.Tire.Any(y => y.TirePressure < 1)))
                {
                    Console.WriteLine($"{car.Model}");
                }
            }
            else
            {
                foreach (var car in cars.Where(x => x.Cargo.CargoType == command && x.Engine.EnginePower > 250))
                {
                    Console.WriteLine($"{car.Model}");
                }
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            List <Car> allCars = new List <Car>();

            int numberOfCars = int.Parse(Console.ReadLine());

            for (int i = 0; i < numberOfCars; i++)
            {
                string[] currentCarInfo = Console.ReadLine().Split();

                string model = currentCarInfo[0];

                double engineSpeed = double.Parse(currentCarInfo[1]);
                double enginePower = double.Parse(currentCarInfo[2]);

                Engine engine = new Engine(engineSpeed, enginePower);

                double cargoWeight = double.Parse(currentCarInfo[3]);
                string cargoType   = currentCarInfo[4];

                Cargo cargo = new Cargo(cargoWeight, cargoType);

                double tire1Pressure = double.Parse(currentCarInfo[5]);
                double tire1Age      = double.Parse(currentCarInfo[6]);

                double tire2Pressure = double.Parse(currentCarInfo[7]);
                double tire2Age      = double.Parse(currentCarInfo[8]);

                double tire3Pressure = double.Parse(currentCarInfo[9]);
                double tire3Age      = double.Parse(currentCarInfo[10]);

                double tire4Pressure = double.Parse(currentCarInfo[11]);
                double tire4Age      = double.Parse(currentCarInfo[12]);

                Tire[] tires = new Tire[4];

                Tire tire1 = new Tire(tire1Age, tire1Pressure);
                Tire tire2 = new Tire(tire2Age, tire2Pressure);
                Tire tire3 = new Tire(tire3Age, tire3Pressure);
                Tire tire4 = new Tire(tire4Age, tire4Pressure);

                tires[0] = tire1;
                tires[1] = tire2;
                tires[2] = tire3;
                tires[3] = tire4;

                Car currentCar = new Car(model, engine, cargo, tires);

                allCars.Add(currentCar);
            }

            string cargoModel = Console.ReadLine();

            if (cargoModel == "fragile")
            {
                foreach (var currentCar in allCars)
                {
                    if (currentCar.Cargo.CargoType == cargoModel)
                    {
                        bool isLowPressure = GetTipePressure(currentCar.Tires);

                        if (isLowPressure)
                        {
                            Console.WriteLine(currentCar.Model);
                        }
                    }
                }
            }
            else if (cargoModel == "flamable")
            {
                foreach (var car in allCars)
                {
                    if (car.Engine.EnginePower > 250)
                    {
                        Console.WriteLine(car.Model);
                    }
                }
            }
        }