コード例 #1
0
        static void Main(string[] args)
        {
            List <Car> cars = new List <Car>();

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

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

                string model       = input[0];
                int    engineSpeed = int.Parse(input[1]);
                int    enginePower = int.Parse(input[2]);
                int    cargoWeight = int.Parse(input[3]);
                string cargoType   = input[4];

                double[] tire1 = new double[2];
                tire1[0] = double.Parse(input[5]);
                tire1[1] = double.Parse(input[6]);

                double[] tire2 = new double[2];
                tire2[0] = double.Parse(input[7]);
                tire2[1] = double.Parse(input[8]);

                double[] tire3 = new double[2];
                tire3[0] = double.Parse(input[9]);
                tire3[1] = double.Parse(input[10]);

                double[] tire4 = new double[2];
                tire4[0] = double.Parse(input[11]);
                tire4[1] = double.Parse(input[12]);

                Engine curentEngin = new Engine(engineSpeed, enginePower);
                Cargo  curentCargo = new Cargo(cargoWeight, cargoType);
                Tire[] curentTires = new Tire[]
                {
                    new Tire(tire1[0], tire1[1]),
                    new Tire(tire2[0], tire2[1]),
                    new Tire(tire3[0], tire3[1]),
                    new Tire(tire4[0], tire4[1])
                };

                Car curentCar = new Car(model, curentEngin, curentCargo, curentTires);

                cars.Add(curentCar);
            }

            string comand = Console.ReadLine();

            if (comand == "fragile")
            {
                var print = cars.Where(x => x.Cargo.Type == "fragile" && x.Tires.Any(s => s.Pressure < 1)).ToList();

                foreach (var item in print)
                {
                    Console.WriteLine($"{item.Model}");
                }
            }
            else
            {
                var print = cars.Where(x => x.Cargo.Type == "flamable" && x.Engine.Power > 250).ToList();

                foreach (var item in print)
                {
                    Console.WriteLine($"{item.Model}");
                }
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            int        n    = int.Parse(Console.ReadLine());
            List <Car> cars = new List <Car>();

            for (int i = 0; i < n; i++)
            {
                string[]    inputArgs          = Console.ReadLine().Split(' ');
                string      model              = inputArgs[0];
                int         engineSpeed        = int.Parse(inputArgs[1]);
                int         enginePower        = int.Parse(inputArgs[2]);
                int         cargoWeight        = int.Parse(inputArgs[3]);
                string      cargoType          = inputArgs[4];
                List <Tire> tires              = new List <Tire>();
                double      firstTirePressure  = double.Parse(inputArgs[5]);
                int         firstTireAge       = int.Parse(inputArgs[6]);
                double      secondTirePressure = double.Parse(inputArgs[7]);
                int         secondTireAge      = int.Parse(inputArgs[8]);
                double      thirdTirePressure  = double.Parse(inputArgs[9]);
                int         thirdTireAge       = int.Parse(inputArgs[10]);
                double      fourthTirePressure = double.Parse(inputArgs[11]);
                int         fourthTireAge      = int.Parse(inputArgs[12]);

                Tire firstTire  = new Tire(firstTireAge, firstTirePressure);
                Tire secondTire = new Tire(secondTireAge, secondTirePressure);
                Tire thirdTire  = new Tire(thirdTireAge, thirdTirePressure);
                Tire fourthTire = new Tire(fourthTireAge, fourthTirePressure);
                tires.Add(firstTire);
                tires.Add(secondTire);
                tires.Add(thirdTire);
                tires.Add(fourthTire);

                //for (int j = 0; j <= 6; j += 2)
                //{
                //	double tirePressure = double.Parse(inputArgs[5 + j]);
                //	int tireAge = int.Parse(inputArgs[6 + j]);

                //	Tire tire = new Tire(tireAge, tirePressure);
                //	tires.Add(tire);
                //}

                Engine engine = new Engine(engineSpeed, enginePower);
                Cargo  cargo  = new Cargo(cargoWeight, cargoType);
                Car    car    = new Car(model, engine, cargo, tires);
                cars.Add(car);
            }

            string     command    = Console.ReadLine();
            List <Car> resultCars = new List <Car>();

            if (command == "fragile")
            {
                resultCars = cars.Where(x => x.Cargo.CargoType == "fragile" && x.Tires.Any(s => s.Pressure < 1)).ToList();
            }
            else
            {
                resultCars = cars.Where(x => x.Cargo.CargoType == "flamable" && x.Engine.Power > 250).ToList();
            }

            foreach (Car c in resultCars)
            {
                Console.WriteLine(c.Model);
            }
        }