예제 #1
0
        public static void Main()
        {
            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];

                List <Tire> tyres = new List <Tire>();

                for (int j = 0; j < 4; j += 2)
                {
                    double tirePressure = double.Parse(input[5 + j]);
                    int    tyreAge      = int.Parse(input[6 + j]);

                    Tire tyre = new Tire(tirePressure, tyreAge);
                    tyres.Add(tyre);
                }

                Engine engine = new Engine(engineSpeed, enginePower);
                Cargo  cargo  = new Cargo(cargoWeight, cargoType);

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

            string typeOfCargo = Console.ReadLine();


            if (typeOfCargo == "fragile")
            {
                cars
                .Where(c => c.Cargo.CargoType == "fragile" && c.Tire.Any(t => t.Pressure < 1))
                .ToList().ForEach(c => Console.WriteLine($"{c.Model}"));
            }
            else
            {
                cars
                .Where(c => c.Cargo.CargoType == "flamable" && c.Engine.EnginePower > 250)
                .ToList()
                .ForEach(c => Console.WriteLine($"{c.Model}"));
            }
        }
예제 #2
0
        public static void Main()
        {
            var count = int.Parse(Console.ReadLine());

            var cars = new List <Car>();

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

                var engine  = new Engine(engineSpeed, enginePower);
                var cargo   = new Cargo(cargoType, cargoWeight);
                var tires   = new Tire[4];
                var counter = 0;
                for (int j = 0; j < 8; j += 2)
                {
                    var tirePressure = double.Parse(carInfo[5 + j]);
                    var tireAge      = int.Parse(carInfo[6 + j]);
                    var currentTire  = new Tire(tirePressure, tireAge);
                    tires[counter] = currentTire;
                    counter++;
                }

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

            var result = new List <Car>();

            var cargotype = Console.ReadLine();

            if (cargotype.Equals("fragile"))
            {
                result = cars.Where(c => c.Cargo.Type.Equals("fragile") && c.Tires.Any(t => t.Pressure < 1)).ToList();
            }
            else
            {
                result = cars.Where(c => c.Cargo.Type.Equals("flamable") && c.Engine.Power > 250).ToList();
            }

            foreach (var car in result)
            {
                Console.WriteLine(car.Model);
            }
        }
예제 #3
0
        static void Main()
        {
            int        n    = int.Parse(Console.ReadLine());
            List <Car> cars = new List <Car>();

            for (int i = 0; i < n; i++)
            {
                var info          = Console.ReadLine().Split();
                var model         = info[0];
                var engineSpeed   = int.Parse(info[1]);
                var enginePower   = int.Parse(info[2]);
                var cargoWeight   = int.Parse(info[3]);
                var cargoType     = info[4];
                var tire1Pressure = double.Parse(info[5]);
                var tire1Age      = int.Parse(info[6]);
                var tire2Pressure = double.Parse(info[5]);
                var tire2Age      = int.Parse(info[6]);
                var tire3Pressure = double.Parse(info[5]);
                var tire3Age      = int.Parse(info[6]);
                var tire4Pressure = double.Parse(info[5]);
                var tire4Age      = int.Parse(info[6]);

                Engine engine = new Engine(engineSpeed, enginePower);
                Cargo  cargo  = new Cargo(cargoWeight, cargoType);
                Tire   tire1  = new Tire(tire1Age, tire1Pressure);
                Tire   tire2  = new Tire(tire2Age, tire2Pressure);
                Tire   tire3  = new Tire(tire3Age, tire3Pressure);
                Tire   tire4  = new Tire(tire4Age, tire4Pressure);
                Car    car    = new Car(model, engine, cargo, tire1, tire2, tire3, tire4);
                cars.Add(car);
            }

            string command = Console.ReadLine();

            if (command == "fragile")
            {
                foreach (var car in cars.Where(c => c.Cargo.CargoType == "fragile" &&
                                               (c.Tire1.TirePressure < 1 || c.Tire2.TirePressure < 1 || c.Tire3.TirePressure < 1 || c.Tire4.TirePressure < 1)))
                {
                    Console.WriteLine(car.Model);
                }
            }
            else
            {
                foreach (var car in cars.Where(c => c.Cargo.CargoType == "flamable" && c.Engine.EnginePower > 250))
                {
                    Console.WriteLine(car.Model);
                }
            }
        }
예제 #4
0
        public static void Main()
        {
            int        n    = int.Parse(Console.ReadLine());
            List <Car> cars = new List <Car>();

            for (int i = 0; i < n; i++)
            {
                Queue <string> input = new Queue <string>(Console.ReadLine()
                                                          .Split(" ", StringSplitOptions.RemoveEmptyEntries));
                string model       = input.Dequeue();
                int    engineSpeed = int.Parse(input.Dequeue());
                int    enginePower = int.Parse(input.Dequeue());
                int    cargoWeight = int.Parse(input.Dequeue());
                string cargoType   = input.Dequeue();

                Engine      engine = new Engine(engineSpeed, enginePower);
                Cargo       cargo  = new Cargo(cargoWeight, cargoType);
                List <Tire> tires  = new List <Tire>();

                while (input.Any())
                {
                    double tirePressure = double.Parse(input.Dequeue());
                    int    tireYear     = int.Parse(input.Dequeue());
                    Tire   tire         = new Tire(tirePressure, tireYear);
                    tires.Add(tire);
                }

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

            string command = Console.ReadLine();

            if (command == "fragile")
            {
                foreach (var car in cars.Where(x => x.Cargo.CargoType == command &&
                                               x.Tire.Any(y => y.Pressure < 1)))
                {
                    Console.WriteLine($"{car.Model}");
                }
            }
            else
            {
                foreach (var car in cars.Where(x => x.Cargo.CargoType == command && x.Engine.EnginePower > 250))
                {
                    Console.WriteLine($"{car.Model}");
                }
            }
        }
예제 #5
0
        public static void Main()
        {
            var cars = new List <Car>();
            var N    = int.Parse(Console.ReadLine());

            for (int i = 0; i < N; i++)
            {
                var carInfo = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                var cargo  = new Cargo(carInfo[4], int.Parse(carInfo[3]));
                var engine = new Engine(int.Parse(carInfo[1]), int.Parse(carInfo[2]));
                var tire1  = new Tire(double.Parse(carInfo[5]), int.Parse(carInfo[6]));
                var tire2  = new Tire(double.Parse(carInfo[7]), int.Parse(carInfo[8]));
                var tire3  = new Tire(double.Parse(carInfo[9]), int.Parse(carInfo[10]));
                var tire4  = new Tire(double.Parse(carInfo[11]), int.Parse(carInfo[12]));

                var car = new Car(carInfo[0], cargo, engine, new List <Tire>()
                {
                    tire1, tire2, tire3, tire4
                });
                cars.Add(car);
            }

            var command = Console.ReadLine();

            switch (command)
            {
            case "fragile":
                var wantedCars = cars.Where(x => x.Cargo.CargoType == "fragile")
                                 .Where(y => y.Tires.Any(z => z.Pressure < 1));

                foreach (var wantedCar in wantedCars)
                {
                    Console.WriteLine(wantedCar.Model);
                }
                break;

            case "flamable":

                foreach (var wantedCar in cars.Where(x => x.Cargo.CargoType == "flamable")
                         .Where(y => y.Engine.EnginePower > 250))
                {
                    Console.WriteLine(wantedCar.Model);
                }
                break;
            }
        }
예제 #6
0
        public static void Main()
        {
            var n    = int.Parse(Console.ReadLine());
            var cars = new List <Car>();

            for (int i = 0; i < n; i++)
            {
                var tokens = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                var model       = tokens[0];
                var engineSpeed = double.Parse(tokens[1]);
                var enginePower = double.Parse(tokens[2]);
                var cargoWeight = double.Parse(tokens[3]);
                var cargoType   = tokens[4];

                var carEngine = new Engine(engineSpeed, enginePower);
                var carCargo  = new Cargo(cargoWeight, cargoType);
                var tires     = new Tire[4]
                {
                    new Tire(double.Parse(tokens[5]), int.Parse(tokens[6])),
                    new Tire(double.Parse(tokens[7]), int.Parse(tokens[8])),
                    new Tire(double.Parse(tokens[9]), int.Parse(tokens[10])),
                    new Tire(double.Parse(tokens[11]), int.Parse(tokens[12]))
                };

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

            var command = Console.ReadLine();

            if (command == "fragile")
            {
                cars
                .Where(c => c.cargo.cargoType == "fragile" && c.tyres.Any(x => x.pressure < 1))
                .ToList()
                .ForEach(c => Console.WriteLine($"{c.model}"));
            }
            else if (command == "flamable")
            {
                cars.Where(c => c.cargo.cargoType == "flamable" && c.engine.enginePower > 250)
                .ToList()
                .ForEach(c => Console.WriteLine($"{c.model}"));
            }
        }
예제 #7
0
        public static void Main()
        {
            int n = int.Parse(Console.ReadLine());

            var carList = new List <Car>();

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

                var engine = new Engine(int.Parse(input[1]), int.Parse(input[2]));
                var cargo  = new Cargo(int.Parse(input[3]), input[4]);

                var tires = new Tire[]
                {
                    new Tire(int.Parse(input[6]), double.Parse(input[5])),
                    new Tire(int.Parse(input[8]), double.Parse(input[7])),
                    new Tire(int.Parse(input[10]), double.Parse(input[9])),
                    new Tire(int.Parse(input[12]), double.Parse(input[11])),
                };

                var currentCar = new Car(input[0], engine, cargo, tires);

                carList.Add(currentCar);
            }

            var command = Console.ReadLine();

            if (command == "fragile")
            {
                foreach (var car in carList.Where(c => c.CarCargo.Type == command).Where(t => t.Tires.Any(x => x.Pressure < 1)))
                {
                    Console.WriteLine(car.Model);
                }
            }
            else if (command == "flamable")
            {
                foreach (var car in carList.Where(c => c.CarCargo.Type == command).Where(t => t.Engine.Power > 250))
                {
                    Console.WriteLine(car.Model);
                }
            }
        }
예제 #8
0
        public static void Main()
        {
            var n       = int.Parse(Console.ReadLine());
            var company = new List <Car>();

            for (int i = 0; i < n; i++)
            {
                var carArg = Console.ReadLine()
                             .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                var model         = carArg[0];
                var engineSpeed   = int.Parse(carArg[1]);
                var enginePower   = int.Parse(carArg[2]);
                var cargoWeight   = int.Parse(carArg[3]);
                var cargoType     = carArg[4];
                var tire1Pressure = double.Parse(carArg[5]);
                var tire1Age      = int.Parse(carArg[6]);
                var tire2Pressure = double.Parse(carArg[7]);
                var tire2Age      = int.Parse(carArg[8]);
                var tire3Pressure = double.Parse(carArg[9]);
                var tire3Age      = int.Parse(carArg[10]);
                var tire4Pressure = double.Parse(carArg[11]);
                var tire4Age      = int.Parse(carArg[12]);

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

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

                var tire1 = new Tire()
                {
                    TirePressure = tire1Pressure,
                    TireAge      = tire1Age
                };
                var tire2 = new Tire()
                {
                    TirePressure = tire2Pressure,
                    TireAge      = tire2Age
                };
                var tire3 = new Tire()
                {
                    TirePressure = tire3Pressure,
                    TireAge      = tire3Age
                };
                var tire4 = new Tire()
                {
                    TirePressure = tire4Pressure,
                    TireAge      = tire4Age
                };

                var car = new Car()
                {
                    Model  = model,
                    Engine = engine,
                    Cargo  = cargo,
                    Tires  = new List <Tire>()
                };
                car.Tires.Add(tire1);
                car.Tires.Add(tire2);
                car.Tires.Add(tire3);
                car.Tires.Add(tire4);

                company.Add(car);
            }
            var command = Console.ReadLine();

            if (command == "fragile")
            {
                company
                .Where(c => c.Cargo.CargoType == "fragile" && c.Tires.Any(t => t.TirePressure < 1))
                .Select(c => c.Model)
                .ToList()
                .ForEach(Console.WriteLine);
            }
            else
            {
                company
                .Where(c => c.Cargo.CargoType == "flamable" && c.Engine.EnginePower > 250)
                .Select(c => c.Model)
                .ToList()
                .ForEach(Console.WriteLine);
            }
        }
예제 #9
0
        static void Main(string[] args)
        {
            int        length = int.Parse(Console.ReadLine());
            List <Car> cars   = new List <Car>();

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

                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];
                Tire[] currentTires = new Tire[4]
                {
                    new Tire(double.Parse(input[5]), int.Parse(input[6])),
                    new Tire(double.Parse(input[7]), int.Parse(input[8])),
                    new Tire(double.Parse(input[9]), int.Parse(input[10])),
                    new Tire(double.Parse(input[11]), int.Parse(input[12])),
                };

                var currentEngine = new Engine(engineSpeed, enginePower);
                var currentCargo  = new Cargo(cargoWeight, cargoType);

                var currentCar = new Car(model, currentEngine, currentCargo, currentTires);
                cars.Add(currentCar);
            }

            string filter = Console.ReadLine();

            if (filter == "fragile")
            {
                var result = cars
                             .Where(x => x.Cargo.CargoType == "fragile")
                             .ToList();

                foreach (var car in result)
                {
                    bool isValid = false;
                    foreach (var tire in car.Tires)
                    {
                        if (tire.Pressure < 1)
                        {
                            isValid = true;
                        }
                    }

                    if (isValid)
                    {
                        Console.WriteLine(car.Model);
                    }
                }
            }
            else
            {
                if (filter == "flamable")
                {
                    var result = cars
                                 .Where(x => x.Cargo.CargoType == "flamable")
                                 .Where(x => x.Engine.Power > 250)
                                 .ToList();

                    foreach (var car in result)
                    {
                        Console.WriteLine(car.Model);
                    }
                }
            }
        }
 public Car(string model, Engine engine, Cargo cargo, Tire tire1, Tire tire2, Tire tire3, Tire tire4)
 {
     Model    = model;
     Engine   = engine;
     Cargo    = cargo;
     tires[0] = tire1;
     tires[1] = tire2;
     tires[2] = tire3;
     tires[3] = tire4;
 }
예제 #11
0
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            Dictionary <string, Car> allCars = new Dictionary <string, Car>();

            for (int i = 0; i < n; i++)
            {
                var input =
                    Console.ReadLine()
                    .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                    .ToArray();
                Car car = new Car();

                List <Tire> tires = new List <Tire>();
                var         model = input[0];

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

                var cargoWeight = int.Parse(input[3]);
                var cargoType   = input[4];

                var  firstP = double.Parse(input[5]);
                var  firstA = int.Parse(input[6]);
                Tire firstT = new Tire(firstP, firstA);

                var  secondP = double.Parse(input[7]);
                var  secondA = int.Parse(input[8]);
                Tire secondT = new Tire(secondP, secondA);

                var  thirdP = double.Parse(input[9]);
                var  thirdA = int.Parse(input[10]);
                Tire thirdT = new Tire(thirdP, thirdA);

                var  fourthP = double.Parse(input[11]);
                var  fourthA = int.Parse(input[12]);
                Tire fourthT = new Tire(fourthP, fourthA);

                tires.Add(firstT);
                tires.Add(secondT);
                tires.Add(thirdT);
                tires.Add(fourthT);

                car.AddCar(
                    model,
                    new Engine(engineSpeed, enginePower),
                    new Cargo(cargoWeight, cargoType),
                    tires);
                allCars[model] = car;
            }

            string command = Console.ReadLine();


            if (command == "fragile")
            {
                allCars
                .Where(x => x.Value.Tire.Any(p => p.Pressure < 1) &&
                       x.Value.Cargo.Type == "fragile")
                .Select(x => x.Key)
                .ToList()
                .ForEach(x => Console.WriteLine(x));
            }
            else if (command == "flamable")
            {
                allCars
                .Where(x => x.Value.Engine.EnginePower > 250 &&
                       x.Value.Cargo.Type == "flamable")
                .Select(x => x.Key)
                .ToList()
                .ForEach(x => Console.WriteLine(x));
            }
        }