public static void Main(string[] args) { int count = int.Parse(Console.ReadLine()); List <Car> cars = new List <Car>(); for (int i = 0; i < count; i++) { string[] inputInfo = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries); string model = inputInfo[0]; int engineSpeed = int.Parse(inputInfo[1]); int enginePower = int.Parse(inputInfo[2]); int cargoWeight = int.Parse(inputInfo[3]); string cargoType = inputInfo[4]; Tire[] tires = new Tire[4]; int counter = 0; for (int j = 5; j < inputInfo.Length; j += 2) { double currentTirePressure = double.Parse(inputInfo[j]); int curretnTireAge = int.Parse(inputInfo[j + 1]); Tire tire = new Tire(currentTirePressure, curretnTireAge); tires[counter] = tire; counter++; } Engine engine = new Engine(engineSpeed, enginePower); Cargo cargo = new Cargo(cargoWeight, cargoType); Car car = new Car(model, engine, cargo, tires); cars.Add(car); } string command = Console.ReadLine(); if (command == "flamable") { cars.Where(x => x.Engine.EnginePower > 250 && x.Cargo.CargoType == "flamable").ToList() .ForEach(x => Console.WriteLine(x.Model)); } else if (command == "fragile") { cars.Where(x => x.Cargo.CargoType == "fragile" && x.Tires.Any(p => p.TirePressure < 1)).ToList() .ForEach(x => Console.WriteLine(x.Model)); } }
public static void Main(string[] args) { int numberOfCars = int.Parse(Console.ReadLine()); List <Car> cars = new List <Car>(); for (int i = 0; i < numberOfCars; i++) { string[] input = Console.ReadLine() .Split() .ToArray(); 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[] tires = new Tire[4]; for (int tireNumber = 5, p = 0; tireNumber < input.Length; tireNumber += 2, p++) { double tirePressure = double.Parse(input[tireNumber]); int tireAge = int.Parse(input[tireNumber + 1]); Tire tire = new Tire(tirePressure, tireAge); tires[p] = tire; } Engine engine = new Engine(engineSpeed, enginePower); Cargo cargo = new Cargo(cargoWeight, cargoType); Car car = new Car(model, engine, cargo, tires); cars.Add(car); } string command = Console.ReadLine(); if (command == "fragile") { cars .Where(car => car.Cargo.CargoType == "fragile" && car.Tires.Any(p => p.TirePressure < 1)) .ToList() .ForEach(x => Console.WriteLine(x.Model)); } else if (command == "flamable") { cars .Where(car => car.Cargo.CargoType == "flamable" && car.Engine.EnginePower > 250) .ToList() .ForEach(x => Console.WriteLine(x.Model)); } }
public static void Main() { var lines = int.Parse(Console.ReadLine()); var cars = new List <Car>(); for (int i = 0; i < lines; i++) { var input = Console.ReadLine().Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToArray(); var tires = new List <Tire>(); 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]; input = input.Skip(5).ToArray(); for (int j = 0; j < input.Length - 1; j += 2) { var currentTirePressure = double.Parse(input[j]); var currentTireAge = int.Parse(input[j + 1]); var tire = new Tire(currentTirePressure, currentTireAge); tires.Add(tire); } var engine = new Engine(engineSpeed, enginePower); var cargo = new Cargo(cargoWeight, cargoType); var car = new Car(model, engine, cargo, tires); cars.Add(car); } var command = Console.ReadLine(); if (command == "fragile") { foreach (var car in cars) { if (car.Cargo.Type == "fragile" && car.Tires.Any(t => t.Pressure < 1)) { Console.WriteLine(car.Model); } } } else if (command == "flamable") { cars .Where(c => c.Cargo.Type == "flamable" && c.Engine.Power > 250) .ToList() .ForEach(c => Console.WriteLine($"{c.Model}")); } }
static void Main(string[] args) { int number = int.Parse(Console.ReadLine()); List <Car> cars = new List <Car>(); for (int i = 0; i < number; i++) { string[] input = Console.ReadLine().Split().ToArray(); Tire[] tireSet = new Tire[4]; for (int j = 0; j < 4; j++) { Tire tire = new Tire(double.Parse(input[5]), int.Parse(input[6])); tireSet[j] = tire; } Car currentCar = new Car(input[0] , new Engine(int.Parse(input[1]), int.Parse(input[2])) , new Cargo(int.Parse(input[3]), input[4]) , tireSet); cars.Add(currentCar); } string command = Console.ReadLine(); //Console.WriteLine(string.Join(Environment.NewLine, cars // .Where(c => c.Cargo.CargoType == command && command == "fragile" // ? c.TireSet // .Where(t => t.TirePressure < 1) // .FirstOrDefault() != null // : c.Engine.EnginePower > 250) // .Select(c => c.Model))); if (command == "fragile") { Console.WriteLine(string.Join(Environment.NewLine, cars .Where(x => x.Cargo.CargoType == "fragile") .Where(x => x.TireSet.Where(t => t.TirePressure < 1).FirstOrDefault() != null) .Select(x => x.Model))); } else { Console.WriteLine(string.Join(Environment.NewLine, cars .Where(x => x.Cargo.CargoType == "flamable") .Where(x => x.Engine.EnginePower > 250) .Select(x => x.Model))); } }
static void Main(string[] args) { List <Car> cars = new List <Car>(); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { var 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]; Tire[] tires = new Tire[4]; int counter = 0; for (int tireIndex = 5; tireIndex < input.Length; tireIndex += 2) { double currentPressure = double.Parse(input[tireIndex]); int currentAge = int.Parse(input[tireIndex + 1]); Tire tire = new Tire(currentPressure, currentAge); tires[counter++] = tire; } Engine engine = new Engine(engineSpeed, enginePower); Cargo cargo = new Cargo(cargoWeight, cargoType); Car car = new Car(model, engine, cargo, tires); cars.Add(car); } var command = Console.ReadLine(); if (command == "flamable") { cars .Where(x => x.Engine.EnginePower > 250 && x.Cargo.CargoType == "flamable") .ToList() .ForEach(x => Console.WriteLine(x.Model)); } else if (command == "fragile") { cars.Where(x => x.Tires.Any(p => p.TirePressure < 1) && x.Cargo.CargoType == "fragile") .ToList() .ForEach(x => Console.WriteLine(x.Model)); } }
void AddTires(string[] tires) { int index = 0; for (int i = 0; i < tires.Length; i++) { double preasure = double.Parse(tires[i]); int age = int.Parse(tires[i + 1]); i++; Tire tire = new Tire(preasure, age); this.Tires[index] = tire; index++; } }
public static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); List <Car> cars = new List <Car>(); for (int i = 0; i < n; i++) { //model} {engineSpeed} {enginePower} {cargoWeight} {cargoType} {tire1Pressure} {tire1Age} {tire2Pressure} {tire2Age} {tire3Pressure} {tire3Age} {tire4Pressure} {tire4Age} string[] cmd = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries); string model = cmd[0]; int engineSpeed = int.Parse(cmd[1]); int enginePower = int.Parse(cmd[2]); int cargoWeight = int.Parse(cmd[3]); string cargoType = cmd[4]; Tire[] currentTires = new Tire[4]; int tireCounter = 0; for (int j = 0; j < 8; j++) { double pressure = double.Parse(cmd[5 + j]); int year = int.Parse(cmd[6 + j]); j++; currentTires[tireCounter] = new Tire(year, pressure); tireCounter++; } cars.Add(new Car(model, new Engine(engineSpeed, enginePower), new Cargo(cargoType, cargoWeight), currentTires)); } string sortType = Console.ReadLine(); if (sortType == "fragile") { foreach (Car c in cars .Where(c => c.Cargo.Type == "fragile" && c.Tires.Any(c => c.Pressure < 1))) { Console.WriteLine($"{c.Model}"); } } else { foreach (Car c in cars .Where(c => c.Cargo.Type == "flamable" && c.CarEngine.Power > 250)) { Console.WriteLine($"{c.Model}"); } } }
static void Main(string[] args) { int numOfCars = int.Parse(Console.ReadLine()); List <Car> cars = new List <Car>(); for (int i = 0; i < numOfCars; i++) { string[] tokens = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries) .ToArray(); string model = tokens[0]; int engineSpeed = int.Parse(tokens[1]); int enginePower = int.Parse(tokens[2]); int cargoWeight = int.Parse(tokens[3]); string cargoType = tokens[4]; double tire1Pressure = double.Parse(tokens[5]); int tire1Age = int.Parse(tokens[6]); double tire2Pressure = double.Parse(tokens[7]); int tire2Age = int.Parse(tokens[8]); double tire3Pressure = double.Parse(tokens[9]); int tire3Age = int.Parse(tokens[10]); double tire4Pressure = double.Parse(tokens[11]); int tire4Age = int.Parse(tokens[12]); Cargo cargo = new Cargo(cargoType, cargoWeight); Engine engine = new Engine(enginePower, engineSpeed); Tire tire = new Tire(tire1Pressure, tire2Pressure, tire3Pressure, tire4Pressure, tire1Age, tire2Age, tire3Age, tire4Age); Car car = new Car(model, cargo, engine, tire); cars.Add(car); } string statement = Console.ReadLine(); List <Car> fragileCar = new List <Car>(); if (statement == "fragile") { fragileCar = cars.Where(x => x.Cargo.CargoType == "fragile" && x.Tire.GetPressure()).ToList(); } else if (statement == "flamable") { fragileCar = cars.Where(x => x.Cargo.CargoType == "flamable" && x.Engine.EnginePower > 250).ToList(); } foreach (var car in fragileCar) { Console.WriteLine(car.Model); } }
public static void Main() { List <string> fragiles = new List <string>(); List <string> flamables = new List <string>(); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { string[] data = Console.ReadLine().Split(); string model = data[0]; int engineSpeed = int.Parse(data[1]); int enginePower = int.Parse(data[2]); int cargoWeight = int.Parse(data[3]); string cargoType = data[4]; double tire1Pressure = double.Parse(data[5]); int tire1Age = int.Parse(data[6]); double tire2Pressure = double.Parse(data[7]); int tire2Age = int.Parse(data[8]); double tire3Pressure = double.Parse(data[9]); int tire3Age = int.Parse(data[10]); double tire4Pressure = double.Parse(data[11]); int tire4Age = int.Parse(data[12]); var tire = new Tire(tire1Pressure, tire2Pressure, tire3Pressure, tire4Pressure); var pressure = tire.TirePressure(); if (cargoType == "fragile" && pressure < 1) { fragiles.Add(model); } else if (cargoType == "flamable" && enginePower > 250) { flamables.Add(model); } } string command = Console.ReadLine(); if (command == "flamable") { Console.WriteLine(string.Join("\r\n", flamables)); } else { Console.WriteLine(string.Join("\r\n", fragiles)); } }
public static void Main() { int countCars = int.Parse(Console.ReadLine()); Garage garage = new Garage(); for (int i = 1; i <= countCars; i++) { string[] carInfo = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries); string model = carInfo[0]; int engineSpeed = int.Parse(carInfo[1]); int enginePower = int.Parse(carInfo[2]); int cargoWeight = int.Parse(carInfo[3]); string cargoType = carInfo[4]; double tire1Pressure = double.Parse(carInfo[5]); int tire1Age = int.Parse(carInfo[6]); double tire2Pressure = double.Parse(carInfo[7]); int tire2Age = int.Parse(carInfo[8]); double tire3Pressure = double.Parse(carInfo[9]); int tire3Age = int.Parse(carInfo[10]); double tire4Pressure = double.Parse(carInfo[11]); int tire4Age = int.Parse(carInfo[12]); Engine engine = new Engine(engineSpeed, enginePower); Cargo cargo = new Cargo(cargoWeight, cargoType); Tire tire1 = new Tire(tire1Pressure, tire1Age); Tire tire2 = new Tire(tire2Pressure, tire2Age); Tire tire3 = new Tire(tire3Pressure, tire3Age); Tire tire4 = new Tire(tire4Pressure, tire4Age); List <Tire> tires = new List <Tire>(); tires.Add(tire1); tires.Add(tire2); tires.Add(tire3); tires.Add(tire4); Car car = new Car(model, engine, cargo, tires); garage.Add(car); } string command = Console.ReadLine(); garage.Print(command); }
static void Main(string[] args) { List <Car> cars = new List <Car>(); int n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; 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[] tires = new Tire[4]; int counter = 0; for (int j = 5; j < input.Length; j += 2) { double currentPressure = double.Parse(input[j]); int currentAge = int.Parse(input[j + 1]); Tire tire = new Tire(currentPressure, currentAge); tires[counter++] = tire; } Cargo cargo = new Cargo(cargoWeight, cargoType); Engine motor = new Engine(engineSpeed, enginePower); Car car = new Car(model, motor, cargo, tires); cars.Add(car); } string command = Console.ReadLine(); if (command == "fragile") { cars.Where(x => x.Cargo.GargoType == command && x.Tires.Any(x => x.TirePressure < 1)) .ToList().ForEach(x => Console.WriteLine(x.Model)); } else if (command == "flamable") { cars.Where(y => y.Cargo.GargoType == command && (y.Engine.EnginePower > 250)) .ToList().ForEach(x => Console.WriteLine(x.Model)); } }
public static void Main(string[] args) { 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]; double[] tiresPressure = { double.Parse(input[5]), double.Parse(input[7]), double.Parse(input[9]), double.Parse(input[11]) }; int[] tiresAge = { int.Parse(input[6]), int.Parse(input[8]), int.Parse(input[10]), int.Parse(input[12]) }; Engine engine = new Engine(engineSpeed, enginePower); Cargo cargo = new Cargo(cargoWeight, cargoType); Tire tire = new Tire(tiresPressure, tiresAge); Car car = new Car(model, engine, cargo, tire); cars.Add(car); } string command = Console.ReadLine(); if (command == "fragile") { foreach (var item in cars.Where(c => c.Cargo.CargoType == "fragile").Where(c => c.Tire.TiresPressure.Any(x => x < 1))) { Console.WriteLine(item.Model); } } else { foreach (var item in cars.Where(c => c.Cargo.CargoType == "flamable").Where(c => c.Engine.EnginePower > 250)) { Console.WriteLine(item.Model); } } }
public static void Main(string[] args) { int size = int.Parse(Console.ReadLine() ?? throw new InvalidOperationException()); List <Car> cars = new List <Car>(); for (int i = 0; i < size; i++) { string[] data = Console.ReadLine()?.Split(" ", StringSplitOptions.RemoveEmptyEntries) ?? new string[] { }; string model = data[0]; int engineSpeed = int.Parse(data[1]); int enginePower = int.Parse(data[2]); int cargoWeight = int.Parse(data[3]); CargoType cargoType = data[4] == "fragile" ? CargoType.Fragile : CargoType.Flammable; double tire1Pressure = double.Parse(data[5]); int tire1Age = int.Parse(data[6]); double tire2Pressure = double.Parse(data[7]); int tire2Age = int.Parse(data[8]); double tire3Pressure = double.Parse(data[9]); int tire3Age = int.Parse(data[10]); double tire4Pressure = double.Parse(data[11]); int tire4Age = int.Parse(data[12]); Engine engine = new Engine(engineSpeed, enginePower); Cargo cargo = new Cargo(cargoType, cargoWeight); Tire[] tires = new Tire[4] { new Tire(tire1Age, tire1Pressure), new Tire(tire2Age, tire2Pressure), new Tire(tire3Age, tire3Pressure), new Tire(tire4Age, tire4Pressure), }; cars.Add(new Car(model, engine, cargo, tires)); } CargoType type = Console.ReadLine() == "fragile" ? CargoType.Fragile : CargoType.Flammable; List <Car> result = type == CargoType.Fragile ? cars.Where(c => c.Cargo.Type == CargoType.Fragile && c.Tires.Any(t => t.Pressure < 1)).ToList() : cars.Where(c => c.Cargo.Type == CargoType.Flammable && c.Engine.Power > 250).ToList(); foreach (var car in result) { Console.WriteLine(car.Model); } }
static void Main(string[] args) { List <Car> cars = new List <Car>(); int number = int.Parse(Console.ReadLine()); for (int i = 0; i < number; i++) { string[] input = Console.ReadLine().Split(); string model = input[0]; int engineSpeed = int.Parse(input[1]); int enginePower = int.Parse(input[2]); Engine engine = new Engine(engineSpeed, enginePower); int cargoWeight = int.Parse(input[3]); string cargoType = input[4]; Cargo cargo = new Cargo(cargoWeight, cargoType); Tire[] tires = new Tire[4]; for (int j = 0; j < 8; j += 2) { double pressure = double.Parse(input[j + 5]); int year = int.Parse(input[j + 6]); Tire tire = new Tire(pressure, year); tires[j / 2] = tire; } Car car = new Car(model, engine, cargo, tires); cars.Add(car); } string command = Console.ReadLine(); Func <Car, string, bool> filter = (c, command) => c.Cargo.Type == command && c.Engine.Power > 250; if (command == "fragile") { filter = (c, command) => c.Cargo.Type == command && c.Tires.Any(t => t.Pressure < 1); } foreach (Car car in cars.Where(c => filter(c, command))) { Console.WriteLine(car.ToString()); } }
public static void Main(string[] args) { int count = int.Parse(Console.ReadLine()); List <Car> cars = new List <Car>(); for (int i = 0; i < count; i++) { string[] carInformation = Console.ReadLine() .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .ToArray(); string model = carInformation[0]; int speed = int.Parse(carInformation[1]); int power = int.Parse(carInformation[2]); int weight = int.Parse(carInformation[3]); string type = carInformation[4]; Engine engine = new Engine(speed, power); Cargo cargo = new Cargo(weight, type); List <Tire> tires = new List <Tire>(); for (int k = 5; k < 9; k += 2) //collection of exactly 4 tires { double pressure = double.Parse(carInformation[k]); int age = int.Parse(carInformation[k + 1]); Tire currentTire = new Tire(pressure, age); tires.Add(currentTire); } Car currentCar = new Car(model, engine, cargo, tires); cars.Add(currentCar); } string command = Console.ReadLine(); Car car = new Car(); car.PrintingResult(command, cars); }
public Car(string model, int speed, int power, int cargoWeight, string cargoType, double tire1Pressure, int tire1Age, double tire2Pressure, int tire2Age, double tire3Pressure, int tire3Age, double tire4Pressure, int tire4Age) { Model = model; Engine = new Engine { EngineSpeed = speed, EnginePower = power }; Cargo = new Cargo { CargoWeight = cargoWeight, CargoType = cargoType }; Tires = new Tire[4]; Tires[0] = new Tire { TirePressure = tire1Pressure, TireAge = tire1Age }; Tires[1] = new Tire { TirePressure = tire2Pressure, TireAge = tire2Age }; Tires[2] = new Tire { TirePressure = tire3Pressure, TireAge = tire3Age }; Tires[3] = new Tire { TirePressure = tire4Pressure, TireAge = tire4Age }; }
public static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); List <Car> cars = new List <Car>(); for (int i = 0; i < n; i++) { string[] tokens = Console.ReadLine() .Split(' ', StringSplitOptions.RemoveEmptyEntries); Engine currEngine = new Engine(int.Parse(tokens[1]), int.Parse(tokens[2])); Cargo currCargo = new Cargo(int.Parse(tokens[3]), tokens[4]); Tire currTire1 = new Tire(double.Parse(tokens[5]), int.Parse(tokens[6])); Tire currTire2 = new Tire(double.Parse(tokens[7]), int.Parse(tokens[8])); Tire currTire3 = new Tire(double.Parse(tokens[9]), int.Parse(tokens[10])); Tire currTire4 = new Tire(double.Parse(tokens[11]), int.Parse(tokens[12])); cars.Add(new Car(tokens[0], currEngine, currCargo, currTire1, currTire2, currTire3, currTire4)); } string input = Console.ReadLine(); if (input == "fragile") { foreach (Car car in cars.Where(x => x.Cargo.Type == "fragile" && (x.Tires[0].Pressure < 1) || x.Tires[1].Pressure < 1 || x.Tires[2].Pressure < 1 || x.Tires[3].Pressure < 1)) { Console.WriteLine(car.Model); } } else if (input == "flamable") { foreach (Car car in cars.Where(x => x.Cargo.Type == "flamable" && x.Engine.Power > 250)) { Console.WriteLine(car.Model); } } }
static void Main(string[] args) { Tire[] tires = new Tire[4] { new Tire(1, 2.5), new Tire(1, 2.1), new Tire(1, 0.5), new Tire(1, 2.3), }; Engine engine = new Engine(560, 6300); Car car = new Car("VM", "MK3", 1992, 250, 9, engine, tires); //car.Make = "VM"; //car.Model = "MK3"; //car.Year = 1992; //car.FuelQuantity = 200; //car.FuelConsumption = 10; // 200 //car.Drive(2000); Console.WriteLine(car.WhoAmI()); //Console.WriteLine($"Make: {car.Make}\nModel: {car.Model}\nYear: {car.Year}"); }
public static void Main(string[] args) { var n = int.Parse(Console.ReadLine()); var cars = new List <Car>(); for (int i = 0; i < n; i++) { var inputInfo = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries); var model = inputInfo[0]; var engineSpeed = int.Parse(inputInfo[1]); var enginPower = int.Parse(inputInfo[2]); var cargoWeight = int.Parse(inputInfo[3]); var cargoType = inputInfo[4]; var tires = new Tire[] { new Tire(double.Parse(inputInfo[5]), int.Parse(inputInfo[6])), new Tire(double.Parse(inputInfo[7]), int.Parse(inputInfo[8])), new Tire(double.Parse(inputInfo[9]), int.Parse(inputInfo[10])), new Tire(double.Parse(inputInfo[11]), int.Parse(inputInfo[12])), }; var engine = new Engine(engineSpeed, enginPower); var cargo = new Cargo(cargoWeight, cargoType); var car = new Car(model, engine, cargo, tires); cars.Add(car); } var command = Console.ReadLine(); if (command == "fragile") { cars = cars .Where(car => car.Cargo.CargoType == "fragile") .Where(car => (car.Tires.Any(p => p.Pressure < 1))) .ToList(); foreach (var car in cars) { Console.WriteLine(car.Model); } } else if (command == "flamable") { cars = cars .Where(car => car.Cargo.CargoType == "flamable") .Where(car => car.Engine.EnginePower > 250) .ToList(); foreach (var car in cars) { Console.WriteLine(car.Model); } } }
static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); var cars = new List <Car>(); for (int i = 0; i < n; i++) { var carInfo = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries); 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 tire1Pressure = double.Parse(carInfo[5]); var tire1Age = int.Parse(carInfo[6]); var tire2Pressure = double.Parse(carInfo[7]); var tire2Age = int.Parse(carInfo[8]); var tire3Pressure = double.Parse(carInfo[9]); var tire3Age = int.Parse(carInfo[10]); var tire4Pressure = double.Parse(carInfo[11]); var tire4Age = int.Parse(carInfo[12]); var engine = new Engine(engineSpeed, enginePower); var cargo = new Cargo(cargoWeight, cargoType); var tires = new Tire[4] { new Tire(tire1Pressure, tire1Age), new Tire(tire2Pressure, tire2Age), new Tire(tire3Pressure, tire3Age), new Tire(tire4Pressure, tire4Age) }; var 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.Type == "fragile") .Where(x => x.Tires[0].Pressure < 1 || x.Tires[1].Pressure < 1 || x.Tires[2].Pressure < 1 || x.Tires[3].Pressure < 1)) { Console.WriteLine(car.Model); } } else if (command == "flamable") { foreach (var car in cars .Where(x => x.Cargo.Type == "flamable") .Where(x => x.Engine.Power > 250)) { Console.WriteLine(car.Model); } } }
public static void Main() { var numberCars = int.Parse(Console.ReadLine()); var cars = new List <Car>(); for (int i = 0; i < numberCars; i++) { var input = Console.ReadLine().Split(' ').ToArray(); var model = input[0]; var engine = new Engine { Speed = int.Parse(input[1]), Power = int.Parse(input[2]) }; var cargo = new Cargo { Weight = int.Parse(input[3]), Type = input[4] }; var tires = new List <Tire>(); var tire1 = new Tire { Pressure = double.Parse(input[5]), Age = int.Parse(input[6]) }; tires.Add(tire1); var tire2 = new Tire { Pressure = double.Parse(input[7]), Age = int.Parse(input[8]) }; tires.Add(tire2); var tire3 = new Tire { Pressure = double.Parse(input[9]), Age = int.Parse(input[10]) }; tires.Add(tire3); var tire4 = new Tire { Pressure = double.Parse(input[11]), Age = int.Parse(input[12]) }; tires.Add(tire4); var newCar = new Car(model, engine, cargo, tires); cars.Add(newCar); } var command = Console.ReadLine(); var answer = new StringBuilder(); if (command == "fragile") { //var searchedCars = cars.Where(c => c.Cargo.Type == command && c.Tires.Where(p => p.Pressure < 1).FirstOrDefault() != null).ToList(); var searchedCars = cars.Where(c => c.Cargo.Type == command) .Where(c => c.Tires.Where(p => p.Pressure < 1).FirstOrDefault() != null) .ToList(); foreach (var car in searchedCars) { answer.Append(car.Model).Append('\n'); } } else { var searchedCars = cars.Where(c => c.Cargo.Type == command).Where(c => c.Engine.Power > 250).ToList(); foreach (var car in searchedCars) { answer.Append(car.Model).Append('\n'); } } Console.WriteLine(answer); }
public static void Main(string[] args) { int numberOfCars = int.Parse(Console.ReadLine()); List <Car> cars = new List <Car>(); for (int i = 0; i < numberOfCars; i++) { string[] tokens = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries); string model = tokens[0]; int engineSpeed = int.Parse(tokens[1]); int enginePower = int.Parse(tokens[2]); int cargoWeight = int.Parse(tokens[3]); string cargoType = tokens[4]; double firstTirePressure = double.Parse(tokens[5]); int firstTireAge = int.Parse(tokens[6]); double secondTirePressure = double.Parse(tokens[7]); int secondTireAge = int.Parse(tokens[8]); double thirdTirePressure = double.Parse(tokens[9]); int thirdTireAge = int.Parse(tokens[10]); double fourthTirePressure = double.Parse(tokens[11]); int fourthTireAge = int.Parse(tokens[12]); Tire firstTire = new Tire(firstTirePressure, firstTireAge); Tire secondTire = new Tire(secondTirePressure, secondTireAge); Tire thirdTire = new Tire(thirdTirePressure, thirdTireAge); Tire fourthTire = new Tire(fourthTirePressure, fourthTireAge); List <Tire> tires = new List <Tire>(4) { firstTire, secondTire, thirdTire, fourthTire }; Engine engine = new Engine(engineSpeed, enginePower); Cargo cargo = new Cargo(cargoWeight, cargoType); Car car = new Car(model, engine, cargo, tires); cars.Add(car); } string command = Console.ReadLine(); if (command == "fragile") { cars .Where(c => c.cargo.cargoType == "fragile") .Where(c => c.tires.Any(t => t.tirePressure < 1)) .Select(m => m.Model) .ToList() .ForEach(m => Console.WriteLine(m)); } else if (command == "flamable") { cars .Where(c => c.cargo.cargoType == "flamable") .Where(e => e.engine.enginePower > 250) .Select(m => m.Model) .ToList() .ForEach(m => Console.WriteLine(m)); } }
public static void Main(string[] args) { int numberCars = int.Parse(Console.ReadLine()); List <Car> cars = new List <Car>(); for (int i = 0; i < numberCars; i++) { string[] carInfo = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries); string model = carInfo[0]; int engineSpeed = int.Parse(carInfo[1]); int enginePower = int.Parse(carInfo[2]); int cargoWeight = int.Parse(carInfo[3]); string cargoType = carInfo[4]; double tire1Pressure = double.Parse(carInfo[5]); int tire1Age = int.Parse(carInfo[6]); double tire2Pressure = double.Parse(carInfo[7]); int tire2Age = int.Parse(carInfo[8]); double tire3Pressure = double.Parse(carInfo[9]); int tire3Age = int.Parse(carInfo[10]); double tire4Pressure = double.Parse(carInfo[11]); int tire4Age = int.Parse(carInfo[12]); Engine engine = new Engine(engineSpeed, enginePower); Cargo cargo = new Cargo(cargoWeight, cargoType); Tire[] tires = new Tire[4] { new Tire(tire1Age, tire1Pressure), new Tire(tire2Age, tire2Pressure), new Tire(tire3Age, tire3Pressure), new Tire(tire4Age, tire4Pressure) }; Car car = new Car(model, engine, cargo, tires); cars.Add(car); } string command = Console.ReadLine(); if (command == "fragile") { cars = cars .Where(car => car.Cargo.CargoType == "fragile") .Where(car => car.IsPressureLessThanOne(car)) .ToList(); //cars = cars // .Where(car => car.Cargo.CargoType == "fragile" && // car.Tires.Any(t => t.TirePressure < 1)) // .ToList(); } if (command == "flamable") { cars = cars .Where(car => car.Cargo.CargoType == "flamable") .Where(car => car.Engine.EnginePower > 250) .ToList(); } //cars.ForEach(car => Console.WriteLine(car.Model)); Console.WriteLine(String.Join(Environment.NewLine, cars)); }
public static void Main() { int carsCount = int.Parse(Console.ReadLine()); var cars = new List <Car>(); for (int i = 0; i < carsCount; i++) { var carInfo = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries) .ToArray(); string model = carInfo[0]; int engineSpeed = int.Parse(carInfo[1]); int enginePower = int.Parse(carInfo[2]); var engine = new Engine(engineSpeed, enginePower); int cargoWeight = int.Parse(carInfo[3]); string cargoType = carInfo[4]; var cargo = new Cargo(cargoWeight, cargoType); var tires = new Tire[4] { new Tire(double.Parse(carInfo[5]), int.Parse(carInfo[6])), new Tire(double.Parse(carInfo[7]), int.Parse(carInfo[8])), new Tire(double.Parse(carInfo[9]), int.Parse(carInfo[10])), new Tire(double.Parse(carInfo[11]), int.Parse(carInfo[12])), }; var car = new Car(model, engine, cargo, tires); cars.Add(car); } string command = Console.ReadLine(); if (command == "fragile") { var result = cars .Where(x => x.Cargo.Type == "fragile") .Where(x => x.Tires.Any(y => y.Pressure < 1)) .ToList(); foreach (var car in result) { Console.WriteLine(car); } } else if (command == "flamable") { var result = cars .Where(x => x.Cargo.Type == "flamable") .Where(x => x.Engine.Power > 250) .ToList(); foreach (var car in result) { Console.WriteLine(car); } } }
public static void Main() { int countCars = int.Parse(Console.ReadLine()); List <Car> cars = new List <Car>(); for (int i = 0; i < countCars; i++) { string[] elements = Console.ReadLine() .Split(" ", StringSplitOptions.RemoveEmptyEntries); string model = elements[0]; int engineSpeed = int.Parse(elements[1]); int enginePower = int.Parse(elements[2]); int cargoWeight = int.Parse(elements[3]); string cargoType = elements[4]; 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]); Engine engine = new Engine(engineSpeed, enginePower); Cargo cargo = new Cargo(cargoWeight, cargoType); Tire[] tires = new Tire[4] { new Tire(tire1Pressure, tire1Age), new Tire(tire2Pressure, tire2Age), new Tire(tire3Pressure, tire3Age), new Tire(tire4Pressure, tire4Age), }; Car car = new Car(model, engine, cargo, tires); cars.Add(car); } string command = Console.ReadLine(); if (command == "fragile") { var result = cars.Where(x => x.Cargo.CargoType == "fragile") .Where(x => x.Tires.Any(p => p.TirePressure < 1)) .ToList(); foreach (var item in result) { Console.WriteLine(item.Model); } } else { var result = cars.Where(x => x.Cargo.CargoType == "flamable") .Where(x => x.Engine.EnginePower > 250) .ToList(); foreach (var item in result) { Console.WriteLine(item.Model); } } }
public Car(string model, Engine engine, Cargo cargo, Tire tire1, Tire tire2, Tire tire3, Tire tire4) { this.Model = model; this.Engine = engine; this.Cargo = cargo; Tires = new Tire[] { tire1, tire2, tire3, tire4 }; }
static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); List <Car> cars = new List <Car>(); for (int i = 0; i < n; i++) { string[] data = Console.ReadLine() .Split(' ', StringSplitOptions.RemoveEmptyEntries); string model = data[0]; int engineSpeed = int.Parse(data[1]); int enginePower = int.Parse(data[2]); int cargoWeight = int.Parse(data[3]); string cargoType = data[4]; double tire1Pressure = double.Parse(data[5]); int tire1Age = int.Parse(data[6]); double tire2Pressure = double.Parse(data[7]); int tire2Age = int.Parse(data[8]); double tire3Pressure = double.Parse(data[9]); int tire3Age = int.Parse(data[10]); double tire4Pressure = double.Parse(data[11]); int tire4Age = int.Parse(data[12]); //FACTORY PATTERN - creating all objects seperately and adding them in the car object Engine engine = CreateEngine(engineSpeed, enginePower); Cargo cargo = CreateCargo(cargoWeight, cargoType); Tire[] tires = new Tire[] { CreateTire(tire1Pressure, tire1Age), CreateTire(tire2Pressure, tire2Age), CreateTire(tire3Pressure, tire3Age), CreateTire(tire4Pressure, tire4Age), }; Car car = new Car(model, engine, cargo, tires); cars.Add(car); } string input = Console.ReadLine(); if (input == "fragile") { foreach (Car car in cars) { if (car.Cargo.CargoType == "fragile" && car.Tires.Any(t => t.Pressure < 1)) { Console.WriteLine(car.Model); } } } else if (input == "flamable") { foreach (Car car in cars) { if (car.Cargo.CargoType == "flamable" && car.Engine.Power > 250) { Console.WriteLine(car.Model); } } } }
static void Main(string[] args) { int n = int.Parse(Console.ReadLine()); Dictionary <string, Car> cars = new Dictionary <string, Car>(); 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]; double tire1Pressure = double.Parse(input[5]); int tire1Age = int.Parse(input[6]); double tire2Pressure = double.Parse(input[7]); int tire2Age = int.Parse(input[8]); double tire3Pressure = double.Parse(input[9]); int tire3Age = int.Parse(input[10]); double tire4Pressure = double.Parse(input[11]); int tire4Age = int.Parse(input[12]); Engine engine = new Engine(engineSpeed, enginePower); Cargo cargo = new Cargo(cargoWeight, cargoType); List <Tire> tires = new List <Tire>(); Tire tire1 = new Tire(tire1Pressure, tire1Age); tires.Add(tire1); Tire tire2 = new Tire(tire2Pressure, tire2Age); tires.Add(tire2); Tire tire3 = new Tire(tire3Pressure, tire3Age); tires.Add(tire3); Tire tire4 = new Tire(tire4Pressure, tire4Age); tires.Add(tire4); cars[model] = new Car(model, engine, cargo); cars[model].Tires = tires; } string command = Console.ReadLine(); if (command == "fragile") { var fragileCars = cars.Where(x => x.Value.Cargo.Type == "fragile").Where(x => x.Value.Tires.Any(y => y.Pressure < 1)).ToArray(); foreach (var item in fragileCars) { Console.WriteLine(item.Key); } } else if (command == "flamable") { var flammableCars = cars.Where(x => x.Value.Cargo.Type == "flamable").Where(x => x.Value.Engine.Power > 250).ToArray(); foreach (var item in flammableCars) { Console.WriteLine(item.Key); } } //foreach (var item in cars) //{ // Console.WriteLine(item.Key); // Console.WriteLine($"{item.Value.Engine.Speed} {item.Value.Engine.Power}"); // Console.WriteLine($"{item.Value.Cargo.Weight} {item.Value.Cargo.Type}"); // foreach (var tire in item.Value.Tires) // { // Console.WriteLine($"{tire.Pressure} {tire.Age}"); // } //} }
static void Main(string[] args) { List <RawData> cars = new List <RawData>(); int carsCount = int.Parse(Console.ReadLine()); for (int i = 0; i < carsCount; i++) { string[] carEntry = Console.ReadLine().Split(" ", StringSplitOptions.RemoveEmptyEntries); //"{model} //{ engineSpeed} {enginePower} //{ cargoWeight} {cargoType} //{ tire1Pressure} {tire1Age} {tire2Pressure} {tire2Age} {tire3Pressure} {tire3Age} {tire4Pressure} {tire4Age} string model = carEntry[0]; int speed = int.Parse(carEntry[1]); int power = int.Parse(carEntry[2]); int weight = int.Parse(carEntry[3]); string cargoType = carEntry[4]; var engine = new Engine(speed, power); var cargo = new Cargo(weight, cargoType); var tire = new Tire[4] { new Tire(double.Parse(carEntry[5]), int.Parse(carEntry[6])), new Tire(double.Parse(carEntry[7]), int.Parse(carEntry[8])), new Tire(double.Parse(carEntry[9]), int.Parse(carEntry[10])), new Tire(double.Parse(carEntry[11]), int.Parse(carEntry[12])) }; RawData car = new RawData(model, engine, cargo, tire); cars.Add(car); } string type = Console.ReadLine(); if (type.ToLower() == "fragile") { foreach (var car in cars.Where(t => t.Cargo.Type == type)) { bool pressureCheck = false; for (int i = 0; i < car.Tires.Length; i++) { if (car.Tires[i].Pressure < 1) { pressureCheck = true; continue; } } if (pressureCheck) { Console.WriteLine(car.Model); } } } else { foreach (var car in cars.Where(t => t.Cargo.Type == type)) { if (car.Engine.Power > 250) { Console.WriteLine(car.Model); } } } foreach (var car in cars) { // car.FuelQuantity -= (20 * car.FuelConsumption); // if (car.Year >= 2017 && car.Engine.HorsePower > 330) // { // double pressureSum = 0; // foreach (var item in car.Tire) // { // pressureSum += item.Pressure; // } // if (pressureSum > 9 && pressureSum < 10) // { // Console.WriteLine($"Make: {car.Make}"); // Console.WriteLine($"Model: {car.Model}"); // Console.WriteLine($"Year: {car.Year}"); // Console.WriteLine($"HorsePowers: {car.Engine.HorsePower}"); // Console.WriteLine($"FuelQuantity: {car.FuelQuantity}"); // } } }