示例#1
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));
            }
        }
示例#2
0
        public static void Main(string[] args)
        {
            int    n       = int.Parse(Console.ReadLine());
            string command = null;

            Car[] cars = new Car[n];
            for (int i = 0; i < n; i++)
            {
                string[] splitedinput          = Console.ReadLine().Split(" ");
                string   carmodel              = splitedinput[0];
                double   fuelamount            = double.Parse(splitedinput[1]);
                double   fuelConsumptionFor1km = double.Parse(splitedinput[2]);
                cars[i] = new Car(carmodel, fuelamount, fuelConsumptionFor1km);
            }
            while (command != "End")
            {
                command = Console.ReadLine();
                if (command == "End")
                {
                    break;
                }
                string[] commands   = command.Split();
                string   carModel   = commands[1];
                double   amountOfKm = double.Parse(commands[2]);
                cars.Where(c => c.Model == carModel).ToList().ForEach(c => c.Drive(amountOfKm));
            }
            foreach (Car car in cars)
            {
                Console.WriteLine("{0} {1:F2} {2}", car.Model, car.FuelAmount, car.TravelledDistance);
            }
        }
示例#3
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];
                decimal  fuelAmount = decimal.Parse(tokens[1]);
                decimal  fuelCost   = decimal.Parse(tokens[2]);
                cars[i] = new Car(model, fuelAmount, fuelCost);
            }

            string command = Console.ReadLine();

            while (command != "End")
            {
                string[] tokens   = command.Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
                string   model    = tokens[1];
                decimal  distance = decimal.Parse(tokens[2]);

                cars.Where(c => c.model == model).ToList().ForEach(c => c.Drive(distance));

                command = Console.ReadLine();
            }

            foreach (Car car in cars)
            {
                Console.WriteLine($"{car.model} {car.fuelAmount:f2} {car.distanceTravelled}");
            }
        }
示例#4
0
        static void Main(string[] args)
        {
            int numOfCars = int.Parse(Console.ReadLine());

            Car[] cars = new Car[numOfCars];
            for (int i = 0; i < numOfCars; i++)
            {
                string[] tokens = Console.ReadLine().Split();
                string   model  = tokens[0];
                string[] engine = tokens.Skip(1).Take(2).ToArray();
                string[] cargo  = tokens.Skip(3).Take(2).ToArray();
                string[] tires  = tokens.TakeLast(8).ToArray();
                Car      car    = new Car(model, engine, cargo, tires);
                cars[i] = car;
            }
            string          parameter = Console.ReadLine();
            Predicate <Car> predicate = c => false;

            if (parameter.Equals("fragile"))
            {
                predicate = c => c.Cargo.Type == parameter && c.LowPressure();
            }
            else if (parameter.Equals("flamable"))
            {
                predicate = c => c.Cargo.Type == parameter && c.Engine.Power > 250;
            }
            var result = cars.Where(c => predicate(c)).Select(c => c.Model);

            Console.WriteLine(string.Join(Environment.NewLine, result));
        }
示例#5
0
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            Car[] cars = new Car[n];
            for (int i = 0; i < n; i++)
            {
                string[] input         = Console.ReadLine().Split();
                var      model         = input[0];
                var      engineSpeed   = int.Parse(input[1]);
                var      enginePower   = int.Parse(input[2]);
                var      cargoWeight   = int.Parse(input[3]);
                var      cargoType     = input[4];
                var      Tire1Pressure = double.Parse(input[5]);
                var      Tire1Age      = int.Parse(input[6]);
                var      Tire2Pressure = double.Parse(input[7]);
                var      Tire2Age      = int.Parse(input[8]);
                var      Tire3Pressure = double.Parse(input[9]);
                var      Tire3Age      = int.Parse(input[10]);
                var      Tire4Pressure = double.Parse(input[11]);
                var      Tire4Age      = int.Parse(input[12]);

                cars[i] = new Car(model, new Engine(enginePower, engineSpeed), new List <Tire> {
                    new Tire(Tire1Age, Tire1Pressure), new Tire(Tire2Age, Tire2Pressure), new Tire(Tire3Age, Tire3Pressure), new Tire(Tire4Age, Tire4Pressure)
                },
                                  new Cargo(cargoType, cargoWeight));
            }
            string typeOfPackedge = Console.ReadLine();

            if (typeOfPackedge == "fragile")
            {
                cars.Where(x => x.cargo.type == "fragile").Where(x => x.tire.Any(c => c.tirePresure < 1)).Select(x => x.model).ToList().ForEach(x => Console.WriteLine(x));;
            }
            else if (typeOfPackedge == "flamable")
            {
                cars.Where(x => x.cargo.type == "flamable").Where(x => x.engine.power > 250).Select(x => x.model).ToList().ForEach(x => Console.WriteLine(x));
            }
        }
示例#6
0
        static void Main(string[] args)
        {
            int numberOfCars = int.Parse(Console.ReadLine());

            var cars = new Car[numberOfCars];

            for (int i = 0; i < numberOfCars; i++)
            {
                var carInfo = Console.ReadLine()
                              .Split();
                Car car = new Car(carInfo);
                cars[i] = car;
            }

            string cargoType = Console.ReadLine();

            foreach (var car in cars.Where(x => x.Cargo.CargoType == cargoType))
            {
                if (cargoType == "flamable")
                {
                    if (car.Engine.Power > 250)
                    {
                        Console.WriteLine(car.Model.ToString());
                    }
                }
                else if (cargoType == "fragile")
                {
                    if (car.Tires.TirePressure.FirstOrDefault() > 1)
                    {
                        continue;
                    }
                    Console.WriteLine(car.Model.ToString());
                }
            }

            //if (cargoType == "fragile" )
            //{
            //    foreach (var car in cars)
            //    {
            //        if (car.Tires.TirePressure.FirstOrDefault()>1)
            //        {
            //            continue;
            //        }
            //        Console.WriteLine(car.Model.ToString());
            //    }
            //}
        }
        public static void Main()
        {
            int index = int.Parse(Console.ReadLine());

            Car[] cars = new Car[index];

            for (int i = 0; i < index; i++)
            {
                string[] carInfo = Console.ReadLine().Split(" ");

                string model                 = carInfo[0];
                double fuelAmount            = double.Parse(carInfo[1]);
                double fuelConsumptionFor1km = double.Parse(carInfo[2]);

                Car car = new Car(model, fuelAmount, fuelConsumptionFor1km);
                cars[i] = car;
            }

            while (true)
            {
                string command = Console.ReadLine();

                if (command == "End")
                {
                    break;
                }

                string[] info = command.Split(" ");

                string carModel   = info[1];
                double amountOfKm = double.Parse(info[2]);

                cars.Where(x => x.Model == carModel).ToList().ForEach(x => x.Drive(amountOfKm));
            }

            foreach (Car car in cars)
            {
                Console.WriteLine("{0} {1:F2} {2}", car.Model, car.FuelAmount, car.TravelledDistance);
            }
        }