Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Dictionary<string, Car> cars = new Dictionary<string, Car>();

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

                var model = input[0];
                var engineSpeed = long.Parse(input[1]);
                var enginePower = long.Parse(input[2]);
                var cargoWeight = long.Parse(input[3]);
                var cargoType = input[4];
                var tier1P = double.Parse(input[5]);
                var tier1A = int.Parse(input[6]);
                var tier2P = double.Parse(input[7]);
                var tier2A = int.Parse(input[8]);
                var tier3P = double.Parse(input[9]);
                var tier3A = int.Parse(input[10]);
                var tier4P = double.Parse(input[11]);
                var tier4A = int.Parse(input[12]);

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

                var tierOne = new Tier(tier1P, tier1A);
                var tierTwo = new Tier(tier2P, tier2A);
                var tierThree = new Tier(tier3P, tier3A);
                var tierFour = new Tier(tier4P, tier4A);
                List<Tier> tiers = new List<Tier> { tierOne, tierTwo, tierThree, tierFour };
                var car = new Car(model, engine, cargo, tiers);
                cars[car.Model] = car;
            }

            var type = Console.ReadLine();
            if (type == "fragile")
            {
                var result = cars.Where(x => x.Value.Tiers.Exists(y => y.TirePressure < 1d));
                foreach (var car in result)
                {
                    Console.WriteLine(car.Key);
                }
            }
            else
            {
                var result = cars.Where(x => x.Value.Engine.EnginePower > 250);
                foreach (var car in result)
                {
                    Console.WriteLine(car.Key);
                }
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            int count = int.Parse(Console.ReadLine());
            Car[] cars = new Car[count];

            for (int i=0; i<count; i++)
            {
                string input = Console.ReadLine();
                string[] tokens = input.Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
                string model = tokens[0];
                int speed = int.Parse(tokens[1]);
                int power = int.Parse(tokens[2]);
                int weight = int.Parse(tokens[3]);
                string type = tokens[4];
                double tyre1Pressure = double.Parse(tokens[5]);
                int tyre1Age = int.Parse(tokens[6]);
                double tyre2Pressure = double.Parse(tokens[7]);
                int tyre2Age = int.Parse(tokens[8]);
                double tyre3Pressure = double.Parse(tokens[9]);
                int tyre3Age = int.Parse(tokens[10]);
                double tyre4Pressure = double.Parse(tokens[11]);
                int tyre4Age = int.Parse(tokens[12]);

                cars[i] = new Car(model, new Engine(speed, power), new Cargo(type, weight), new List<Tyre> { new Tyre(tyre1Pressure, tyre1Age), new Tyre(tyre2Pressure, tyre2Age), new Tyre(tyre3Pressure, tyre3Age), new Tyre(tyre4Pressure, tyre4Age) });
            }

            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.power > 250).Select(c => c.model).ToList().ForEach(m => Console.WriteLine(m));
            }
        }