コード例 #1
0
        public static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            List <Car> cars = new List <Car>();
            int        n    = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                var input       = Console.ReadLine().Split().ToArray();
                var model       = input[0];
                var engineSpeed = int.Parse(input[1]);
                var enginePower = int.Parse(input[2]);
                var cargoWeight = int.Parse(input[3]);
                var cargoType   = input[4];
                var engine      = new Engine(engineSpeed, enginePower);
                var cargo       = new Cargo(cargoType, cargoWeight);
                var tires       = new List <Tire>();
                var tiresSkip   = input.Skip(5).ToArray();
                for (int j = 0; j < tiresSkip.Length; j += 2)
                {
                    var pressure = double.Parse(tiresSkip[j]);
                    var age      = int.Parse(tiresSkip[j + 1]);
                    var tire     = new Tire(pressure, age);
                    tires.Add(tire);
                }
                var currCar = new Car(model, engine, cargo, tires);
                cars.Add(currCar);
            }
            string command = Console.ReadLine();

            Func <List <Car>, string, List <Car> > func = (cars, command) =>
            {
                if (command == "fragile")
                {
                    return(cars.Where(c => c.Cargo.TypeCargo == command &&
                                      c.Tires.Any(t => t.PressureTire < 1)).ToList());
                }
                else
                {
                    return(cars.Where(c => c.Cargo.TypeCargo == command && c.Engine.EnginePower > 250).ToList());
                }
            };

            foreach (Car car in func(cars, command))
            {
                Console.WriteLine(car.ToString());
            }
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            var numberOfCars = int.Parse(Console.ReadLine());
            var cars         = new List <Car>();

            for (int i = 0; i < numberOfCars; i++)
            {
                var carInfo = Console.ReadLine().Split(' ');
                var model   = carInfo[0];

                var engineSpeed = int.Parse(carInfo[1]);
                var enginePower = int.Parse(carInfo[2]);
                var engine      = new Engine(engineSpeed, enginePower);

                var cargoWeight = int.Parse(carInfo[3]);
                var cargoType   = carInfo[4];
                var cargo       = new Cargo(cargoWeight, cargoType);

                var tires = new List <Tire>();
                for (int j = 5; j < 12; j += 2)
                {
                    var TirePressure = double.Parse(carInfo[j]);
                    var TireAge      = int.Parse(carInfo[j + 1]);
                    var tire         = new Tire(TirePressure, TireAge);
                    tires.Add(tire);
                }

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

            var command  = Console.ReadLine();
            var selected = new List <Car>();

            switch (command)
            {
            case "fragile":
                selected = cars.Where(c =>

                                      c.Cargo.Type == "fragile" &&
                                      c.Tires.Any(t => t.Pressure < 1)

                                      ).ToList();

                break;

            case "flammable":
                selected = cars.Where(c =>

                                      c.Cargo.Type == "flammable" &&
                                      c.Engine.Power > 250

                                      ).ToList();
                break;
            }

            foreach (var car in selected)
            {
                Console.WriteLine(car.Model);
            }
        }