static void Main(string[] args) { string[] allPeoplesAndMoney = Console.ReadLine().Split(";", StringSplitOptions.RemoveEmptyEntries); string[] allProductsAndCosts = Console.ReadLine().Split(";", StringSplitOptions.RemoveEmptyEntries); List <Person> peoples = new List <Person>(allPeoplesAndMoney.Length); foreach (var people in allPeoplesAndMoney) { string[] currPersonNameAndMoney = people.Split("="); Person currPerson = new Person(currPersonNameAndMoney[0], double.Parse(currPersonNameAndMoney[1])); peoples.Add(currPerson); } List <Product> products = new List <Product>(allProductsAndCosts.Length); foreach (var product in allProductsAndCosts) { string[] currProductAndCost = product.Split("="); Product currProduct = new Product(currProductAndCost[0], double.Parse(currProductAndCost[1])); products.Add(currProduct); } string command = Console.ReadLine(); while (command != "END") { string[] currComand = command.Split(); string name = currComand[0]; string product = currComand[1]; Person currPerson = peoples.FirstOrDefault(n => n.Name == name); Product currProduct = products.FirstOrDefault(p => p.Name == product); peoples.Average(x => x.Money); if (currPerson.HasEnoughMoney(currProduct)) { currPerson.BuyProduct(currProduct); Console.WriteLine($"{name} bought {product}"); } else { Console.WriteLine($"{name} can't afford {product}"); } command = Console.ReadLine(); } foreach (var person in peoples) { Console.WriteLine(person); } }
static void Main() { string[] people = Console.ReadLine().Split(";", StringSplitOptions.RemoveEmptyEntries), products = Console.ReadLine().Split(";", StringSplitOptions.RemoveEmptyEntries); List <Person> personList = new List <Person>(); foreach (string person in people) { personList.Add(new Person(person.Split("=")[0], double.Parse(person.Split("=")[1]))); } List <Product> productList = new List <Product>(); foreach (string product in products) { productList.Add(new Product(product.Split("=")[0], double.Parse(product.Split("=")[1]))); } string[] command = Console.ReadLine().Split(); while (command[0] != "END") { string name = command[0]; string product = command[1]; Person currPerson = personList.FirstOrDefault(n => n.Name == name); Product currProduct = productList.FirstOrDefault(p => p.ProductName == product); if (currPerson.HasEnoughMoney(currProduct)) { currPerson.BuyProduct(currProduct); Console.WriteLine($"{name} bought {product}"); } else { Console.WriteLine($"{name} can't afford {product}"); } command = Console.ReadLine().Split(); } foreach (var person in personList) { Console.WriteLine(person); } }