public static void PrintAllProducts(Product[] products) { Console.WriteLine("------- All products: -------"); foreach (var product in products) { Console.WriteLine("- {0}", product); } Console.WriteLine("-----------------------------\n"); }
/// <summary> /// Parse input using Regular Expressions - Regex.Matches() method /// </summary> public static void ParseInput(out Product[] products, out int maximalWeight) { maximalWeight = int.Parse(Console.ReadLine()); int N = int.Parse(Console.ReadLine()); products = new Product[N]; for (int i = 0; i < N; i++) { var line = Console.ReadLine(); var productName = Regex.Matches(line, @"(\w+).-") .Cast<Match>() .First() .Groups[1].Value; var productCharacteristics = Regex.Matches(line, @"(\w+=)+(\d+)") .Cast<Match>() .Select(a => int.Parse(a.Groups[2].Value)) .ToArray(); products[i] = new Product(productName, productCharacteristics[0], productCharacteristics[1]); } }
private static Product[] ParseInput(int foodCount) { var foods = new Product[foodCount]; for (int i = 0; i < foodCount; i++) { var splittedLine = Console.ReadLine().Split(' '); foods[i] = new Product(splittedLine[0], int.Parse(splittedLine[1]), int.Parse(splittedLine[2])); } return foods; }