コード例 #1
0
        public static void Main()
        {
            var cars    = new List <Car>();
            var tires   = new List <Tire[]>();
            var engines = new List <Engine>();

            string[] tiresInfo = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);

            while (tiresInfo[0] != "No")
            {
                var currentTires = new Tire[4];
                int counter      = 0;

                for (int i = 0; i < tiresInfo.Length / 2; i++)
                {
                    int    year     = int.Parse(tiresInfo[counter]);
                    double pressure = double.Parse(tiresInfo[counter + 1]);
                    counter += 2;

                    currentTires[i] = new Tire(year, pressure);
                }

                tires.Add(currentTires);

                tiresInfo = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
            }

            string[] enginesInfo = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);

            while (enginesInfo[0] != "Engines")
            {
                int    horsePower    = int.Parse(enginesInfo[0]);
                double cubicCapacity = double.Parse(enginesInfo[1]);

                var engine = new Engine(horsePower, cubicCapacity);

                engines.Add(engine);

                enginesInfo = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
            }

            string[] carInfo = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);

            while (carInfo[0] != "Show" && carInfo[1] != "special")
            {
                string make            = carInfo[0];
                string model           = carInfo[1];
                int    year            = int.Parse(carInfo[2]);
                double fuelQuantity    = int.Parse(carInfo[3]);
                double fuelConsumption = int.Parse(carInfo[4]);
                int    engineIndex     = int.Parse(carInfo[5]);
                int    tiresIndex      = int.Parse(carInfo[6]);

                Engine engine = engines[engineIndex];
                Tire[] tire   = tires[tiresIndex];

                var car = new Car(make, model, year, fuelQuantity, fuelConsumption, engine, tire);
                cars.Add(car);

                carInfo = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries);
            }



            var specialCars = cars
                              .Where(x => x.Drive(20) == true)
                              .Where(y => y.Year >= 2017)
                              .Where(h => h.Engine.HorsePower >= 330)
                              .Where(t => t.Tires.Sum(x => x.Pressure) >= 9 && t.Tires.Sum(x => x.Pressure) <= 10)
                              .ToList();

            foreach (var car in specialCars)
            {
                Console.WriteLine(car.WhoAmI());
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: KChavdarov/SoftUni
        static void Main(string[] args)
        {
            var    tires = new List <List <Tire> >();
            string input = Console.ReadLine();
            int    count = 0;

            while (input != "No more tires")
            {
                string[] tokens = input.Split(' ');
                tires.Add(new List <Tire>());

                for (int i = 0; i < tokens.Length; i++)
                {
                    int    year     = int.Parse(tokens[i]);
                    double pressure = double.Parse(tokens[++i]);
                    Tire   tire     = new Tire(year, pressure);
                    tires[count].Add(tire);
                }

                count++;
                input = Console.ReadLine();
            }

            List <Engine> engines = new List <Engine>();

            input = Console.ReadLine();
            while (input != "Engines done")
            {
                string[] tokens     = input.Split(' ');
                int      horsePower = int.Parse(tokens[0]);
                double   capacity   = double.Parse(tokens[1]);
                Engine   engine     = new Engine(horsePower, capacity);
                engines.Add(engine);
                input = Console.ReadLine();
            }

            input = Console.ReadLine();
            List <Car> cars = new List <Car>();

            while (input != "Show special")
            {
                string[] tokens         = input.Split(' ');
                string   make           = tokens[0];
                string   model          = tokens[1];
                int      year           = int.Parse(tokens[2]);
                int      fuelQuantity   = int.Parse(tokens[3]);
                double   fuelConsumtion = double.Parse(tokens[4]);
                Engine   engine         = engines[int.Parse(tokens[5])];
                Tire[]   tireSet        = tires[int.Parse(tokens[6])].ToArray();
                Car      car            = new Car(make, model, year, fuelQuantity, fuelConsumtion, engine, tireSet);
                cars.Add(car);

                input = Console.ReadLine();
            }
            Func <double, bool> isBetween9and10 = num => num > 9 && num < 10;

            var specialCars = cars.Where(a => a.Year == 2017 && a.Engine.HorsePower > 330 && isBetween9and10(a.Tires.Sum(a => a.Pressure))).ToList();

            specialCars.ForEach(a => a.Drive(20));
            specialCars.ForEach(Console.WriteLine);
        }