예제 #1
0
        static void Main(string[] args)
        {
            //"{model} {engineSpeed} {enginePower} {cargoWeight} {cargoType} {tire1Pressure} {tire1Age} {tire2Pressure} {tire2Age} {tire3Pressure} {tire3Age} {tire4Pressure} {tire4Age}"
            List <Car> cars = new List <Car>();

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

            for (int i = 0; i < n; i++)
            {
                string[] carInfo = Console.ReadLine()
                                   .Split(' ', StringSplitOptions.RemoveEmptyEntries);

                string model         = carInfo[0];
                int    speed         = int.Parse(carInfo[1]);
                int    power         = int.Parse(carInfo[2]);
                int    cargoWeight   = int.Parse(carInfo[3]);
                string cargoType     = carInfo[4];
                double tirePressure1 = double.Parse(carInfo[5]);
                int    tireAge1      = int.Parse(carInfo[6]);
                double tirePressure2 = double.Parse(carInfo[7]);
                int    tireAge2      = int.Parse(carInfo[8]);
                double tirePressure3 = double.Parse(carInfo[9]);
                int    tireAge3      = int.Parse(carInfo[10]);
                double tirePressure4 = double.Parse(carInfo[11]);
                int    tireAge4      = int.Parse(carInfo[12]);

                Engine carEngine = new Engine(speed, power);
                Cargo  carCargo  = new Cargo(cargoWeight, cargoType);
                Tire[] carTires  = new Tire[4];
                Tire   tire1     = new Tire(tirePressure1, tireAge1);
                Tire   tire2     = new Tire(tirePressure2, tireAge2);
                Tire   tire3     = new Tire(tirePressure3, tireAge3);
                Tire   tire4     = new Tire(tirePressure4, tireAge4);
                carTires[0] = tire1;
                carTires[1] = tire2;
                carTires[2] = tire3;
                carTires[3] = tire4;

                Car car = new Car(model, carEngine, carCargo, carTires);
                cars.Add(car);
            }

            string command = Console.ReadLine();

            if (command == "fragile")
            {
                cars = cars.Where(c => c.CarCargo.CargoType == "fragile")
                       .Where(c => c.CarTires[0].TirePressure <= 1)
                       .ToList();
            }
            else if (command == "flamable")
            {
                cars = cars.Where(c => c.CarCargo.CargoType == "flamable")
                       .Where(c => c.CarEngine.EnginePower > 250)
                       .ToList();
            }

            foreach (var car in cars)
            {
                Console.WriteLine(car.Model);
            }
        }
예제 #2
0
파일: Program.cs 프로젝트: MartiHr/Softuni
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            HashSet <Car> cars = new HashSet <Car>();

            for (int i = 0; i < n; i++)
            {
                string[] elements = Console.ReadLine()
                                    .Split(" ", StringSplitOptions.RemoveEmptyEntries);

                string model = elements[0];

                int engineSpeed = int.Parse(elements[1]);
                int enginePower = int.Parse(elements[2]);

                Engine engine = new Engine
                {
                    EnginePower = enginePower,
                    EngineSpeed = engineSpeed
                };

                int    cargoWeight = int.Parse(elements[3]);
                string cargoType   = elements[4];

                Cargo cargo = new Cargo
                {
                    CargoWeight = cargoWeight,
                    CargoType   = cargoType
                };

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

                Tire[] tires = new Tire[4]
                {
                    new Tire(tire1Pressure, tire1Age),
                    new Tire(tire2Pressure, tire2Age),
                    new Tire(tire3Pressure, tire3Age),
                    new Tire(tire4Pressure, tire4Age)
                };

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

                cars.Add(currentCar);
            }

            string command = Console.ReadLine();

            if (command == "fragile")
            {
                HashSet <Car> fragileCars = cars
                                            .Where(x => x.Cargo.CargoType == "fragile")
                                            .Where(x => TiresPressurexIfBelow1(x.Tires))
                                            .ToHashSet();

                foreach (var car in fragileCars)
                {
                    Console.WriteLine(car.Model);
                }
            }
            else
            {
                HashSet <Car> flamableCars = cars
                                             .Where(x => x.Cargo.CargoType == "flamable")
                                             .Where(x => x.Engine.EnginePower > 250)
                                             .ToHashSet();

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