コード例 #1
0
 public Car(string model, Engine engine, Cargo cargo, Tires tires)
 {
     Model  = model;
     Engine = engine;
     Cargo  = cargo;
     Tires  = tires;
 }
コード例 #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++)
            {
                var infoForCars = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);

                string model         = infoForCars[0];
                int    engineSpeed   = int.Parse(infoForCars[1]);
                int    enginePower   = int.Parse(infoForCars[2]);
                int    cargoWeight   = int.Parse(infoForCars[3]);
                string cargoType     = infoForCars[4];
                double pressure1Tire = double.Parse(infoForCars[5]);
                int    age1Tire      = int.Parse(infoForCars[6]);
                double pressure2Tire = double.Parse(infoForCars[7]);
                int    age2Tire      = int.Parse(infoForCars[8]);
                double pressure3Tire = double.Parse(infoForCars[9]);
                int    age3Tire      = int.Parse(infoForCars[10]);
                double pressure4Tire = double.Parse(infoForCars[11]);
                int    age4Tire      = int.Parse(infoForCars[12]);

                Engine  engine = new Engine(engineSpeed, enginePower);
                Cargo   cargo  = new Cargo(cargoType, cargoWeight);
                Tires[] tires  = new Tires[4];
                {
                    tires[0] = new Tires(pressure1Tire, age1Tire);
                    tires[1] = new Tires(pressure2Tire, age2Tire);
                    tires[2] = new Tires(pressure3Tire, age3Tire);
                    tires[3] = new Tires(pressure4Tire, age4Tire);
                }

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

            string input = Console.ReadLine();

            if (input == "fragile")
            {
                foreach (Car currentCar in cars.Where(x => x.Cargo.CargoType == "fragile"))
                {
                    if (currentCar.Tires.Any(x => x.TirePressure < 1))
                    {
                        Console.WriteLine($"{currentCar.Model}");
                    }
                }
            }

            if (input == "flamable")
            {
                foreach (Car currentCar in cars.Where(x => x.Cargo.CargoType == "flamable")
                         .Where(x => x.Engine.EnginePower > 250))
                {
                    Console.WriteLine($"{currentCar.Model}");
                }
            }
        }
コード例 #3
0
        public 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];

                Tires[] tiresInfo = new Tires[4];
                int     counter   = 0;

                for (int tireIndex = 5; tireIndex < input.Length; tireIndex += 2)
                {
                    double pressure = double.Parse(input[tireIndex]);
                    int    age      = int.Parse(input[tireIndex + 1]);

                    Tires tires = new Tires(pressure, age);

                    tiresInfo[counter++] = tires;
                }

                Engine engine = new Engine(engineSpeed, enginePower);
                Cargo  cargo  = new Cargo(cargoWeight, cargoType);
                Car    car    = new Car(model, engine, cargo, tiresInfo);

                cars.Add(car);
            }

            string command = Console.ReadLine();

            if (command == "fragile")
            {
                cars.Where(x => x.Cargo.Type == "fragile" && x.Tires.Any(p => p.Perssure < 1))
                .ToList()
                .ForEach(x => Console.WriteLine(x.Model));
            }
            else if (command == "flamable")
            {
                cars
                .Where(x => x.Engine.Power > 250 && x.Cargo.Type == "flamable")
                .ToList()
                .ForEach(x => Console.WriteLine(x.Model));
            }
        }
コード例 #4
0
        private static Car CarFactory(string lineInput)
        {
            string[] lineSplit = lineInput.Split(' ', StringSplitOptions.RemoveEmptyEntries);
            string   model     = lineSplit[0];
            //{model} //{engineSpeed} {enginePower} //{cargoWeight} {cargoType}// {tire1Pressure} {tire1Age} {tire2Pressure} {tire2Age} {tire3Pressure} {tire3Age} {tire4Pressure} {tire4Age}"
            //ChevroletAstro //200 180// 1000 fragile 1.3 1 1.5 2 1.4 2 1.7 4
            Engine carEngine = EngineFactory(lineSplit[1], lineSplit[2]);
            Cargo  carCargo  = CargoFactory(lineSplit[3], lineSplit[4]);
            Tires  tires     = TiresFactory(lineSplit[5], lineSplit[6],
                                            lineSplit[7], lineSplit[8],
                                            lineSplit[9], lineSplit[10],
                                            lineSplit[11], lineSplit[12]);
            Car car = new Car(model, carEngine, carCargo, tires);

            return(car);
        }
コード例 #5
0
        private static void Main(string[] args)
        {
            var count = int.Parse(Console.ReadLine());

            var cars = new List <Car>();

            for (int i = 0; i < count; i++)
            {
                var tokens = Console.ReadLine()
                             .Split(" ", StringSplitOptions.RemoveEmptyEntries);

                var model  = tokens[0];
                var speed  = int.Parse(tokens[1]);
                var power  = int.Parse(tokens[2]);
                var weight = int.Parse(tokens[3]);
                var type   = tokens[4];

                var tires = new List <Tires>();

                for (int j = 5; j < tokens.Length; j += 2)
                {
                    var pressure = double.Parse(tokens[j]);
                    var age      = int.Parse(tokens[j + 1]);

                    Tires tireInfo = new Tires(pressure, age);
                    tires.Add(tireInfo);
                }

                Engine engine  = new Engine(speed, power);
                Cargo  cargo   = new Cargo(type, weight);
                Car    carInfo = new Car(model, engine, cargo, tires);

                cars.Add(carInfo);
            }

            string command = Console.ReadLine();

            if (command == "fragile")
            {
                cars.Where(c => c.cargo.Type == "fragile").Where(c => c.tires.Any(t => t.pressure < 1)).Select(c => c.model).ToList().ForEach(m => Console.WriteLine(m));
            }
            else if (command == "flamable")
            {
                cars.Where(c => c.cargo.Type == "flamable").Where(c => c.engine.EnginePower > 250).Select(c => c.model).ToList().ForEach(m => Console.WriteLine(m));
            }
        }
コード例 #6
0
        static void Main(string[] args)
        {
            List <Car> carList      = new List <Car>();
            int        numberOfCars = int.Parse(Console.ReadLine());

            for (int i = 1; i <= numberOfCars; i++)
            {
                var data = Console.ReadLine()
                           .Split(" ", StringSplitOptions.RemoveEmptyEntries)
                           .ToArray();
                string  model  = data[0];
                Engine  engine = new Engine(int.Parse(data[1]), int.Parse(data[2]));
                Cargo   cargo  = new Cargo(int.Parse(data[3]), data[4]);
                Tires[] tire   = new Tires[]
                {
                    new Tires(int.Parse(data[6]), double.Parse(data[5])),
                    new Tires(int.Parse(data[8]), double.Parse(data[7])),
                    new Tires(int.Parse(data[10]), double.Parse(data[9])),
                    new Tires(int.Parse(data[12]), double.Parse(data[11]))
                };
                Car car = new Car(engine, cargo, model, tire);
                carList.Add(car);
            }
            string input = Console.ReadLine();

            if (input == "fragile")
            {
                carList
                .Where(x => x.Tire.Any(t => t.Pressure < 1))
                .Where(x => x.Cargo.Type == "fragile")
                .ToList()
                .ForEach(x => Console.WriteLine(x.Model));
            }
            else if (input == "flamable")
            {
                carList
                .Where(x => x.Engine.Power > 250)
                .Where(x => x.Cargo.Type == "flamable")
                .ToList()
                .ForEach(x => Console.WriteLine(x.Model));
            }
        }
コード例 #7
0
        private static Tires TiresFactory(string pressureInput, string ageInput,
                                          string pressure1Input, string age1Input,
                                          string pressure2Input, string age2Input,
                                          string pressure3Input, string age3Input)
        {
            double pressure  = double.Parse(pressureInput);
            int    age       = int.Parse(ageInput);
            double pressure1 = double.Parse(pressure1Input);
            int    age1      = int.Parse(age1Input);
            double pressure2 = double.Parse(pressure2Input);
            int    age2      = int.Parse(age2Input);
            double pressure3 = double.Parse(pressure3Input);
            int    age3      = int.Parse(age3Input);
            Tires  tires     = new Tires(pressure, age,
                                         pressure1, age1,
                                         pressure2, age2,
                                         pressure3, age3);

            return(tires);
        }
コード例 #8
0
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            //“<Model> <EngineSpeed> <EnginePower> <CargoWeight> <CargoType> <Tire1Pressure> <Tire1Age> <Tire2Pressure> <Tire2Age> <Tire3Pressure> <Tire3Age> <Tire4Pressure> <Tire4Age>”
            List <Car> cars = new List <Car>();

            for (int i = 0; i < n; i++)
            {
                string[] carArgs     = Console.ReadLine().Split();
                string   model       = carArgs[0];
                int      engineSpeed = int.Parse(carArgs[1]);
                int      enginePower = int.Parse(carArgs[2]);
                int      cargoWeight = int.Parse(carArgs[3]);
                string   cargoType   = carArgs[4];

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

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

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

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

                Engine currentEngine = new Engine(engineSpeed, enginePower);
                Cargo  currentCargo  = new Cargo {
                    CargoType = cargoType, CargoWeight = cargoWeight
                };
                Tires currenTires = new Tires();
                currenTires.AddPressureTires(tire1Pressure, tire2Pressure, tire3Pressure, tire4Pressure);

                Car currentCar = new Car(model, currentEngine, currentCargo, currenTires);

                cars.Add(currentCar);
            }

            string command = Console.ReadLine();

            if (command == "fragile")
            {
                var printCar = cars.Where(a => a.Cargo.CargoType == "fragile");
                printCar = printCar.Where(a => a.Tires.pressureTires.Any(b => b < 1.0));

                foreach (Car car in printCar)
                {
                    Console.WriteLine(car.Model);
                }
            }
            else if (command == "flamable")
            {
                var printCar = cars.Where(a => a.Cargo.CargoType == "flamable" && a.Engine.EnginePower > 250);
                foreach (Car car in printCar)
                {
                    Console.WriteLine(car.Model);
                }
            }
        }