示例#1
0
 public Car(string model, CarEgine engine, Cargo cargo, List <Tire> tires)
 {
     this.Model  = model;
     this.Cargo  = cargo;
     this.Engine = engine;
     this.Tires  = tires;
 }
示例#2
0
        public static void Main()
        {
            var cars = new List <Car>();

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

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

                string carModel    = inputArgs[0];
                int    engineSpeed = int.Parse(inputArgs[1]);
                int    enginePower = int.Parse(inputArgs[2]);
                var    engine      = new CarEgine(enginePower, enginePower);

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

                double tire1Pressure = double.Parse(inputArgs[5]);
                int    tire1Age      = int.Parse(inputArgs[6]);
                double tire2Pressure = double.Parse(inputArgs[7]);
                int    tire2Age      = int.Parse(inputArgs[8]);
                double tire3Pressure = double.Parse(inputArgs[9]);
                int    tire3Age      = int.Parse(inputArgs[10]);
                double tire4Pressure = double.Parse(inputArgs[11]);
                int    tire4Age      = int.Parse(inputArgs[12]);

                var tires = new List <Tire>
                {
                    new Tire(tire1Pressure, tire1Age),
                    new Tire(tire2Pressure, tire2Age),
                    new Tire(tire3Pressure, tire3Age),
                    new Tire(tire4Pressure, tire4Age)
                };

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

            string command = Console.ReadLine();

            IEnumerable <string> wantedCars = null;

            if (command == "fragile")
            {
                wantedCars = cars
                             .Where(c => c.Cargo.Type == "fragile" &&
                                    c.Tires.Any(t => t.Pressure < 1))
                             .Select(c => c.Model);
            }

            else if (command == "flamable")
            {
                wantedCars = cars
                             .Where(c => c.Cargo.Type == "flamable" &&
                                    c.Engine.Power > 250)
                             .Select(c => c.Model);
            }

            Console.WriteLine(string.Join("\n", wantedCars));
        }