private static void FindProductsByProducer(string[] elements, ShoppingCenter shoppingCenter) { var producer = elements[0]; var products = shoppingCenter.FindProductsByProducer(producer); PrintProducts(products); }
private static void FindProductsByProducer(ShoppingCenter shoppingCenter, string line) { var productTokens = SplitLine(line); var producer = productTokens[0].Substring(productTokens[0].IndexOf(" ") + 1); var products = shoppingCenter.FindProductsByProducer(producer); PrintProducts(products); }
private static void FindProductsByProducer(ShoppingCenter shoppingCenter, string[] args) { if (!args.Any()) { return; } var result = shoppingCenter.FindProductsByProducer(args[0]); Print(result); }
static void Main(string[] args) { var lines = int.Parse(Console.ReadLine()); var center = new ShoppingCenter(); for (int i = 0; i < lines; i++) { var input = Console.ReadLine(); var index = input.IndexOf(' '); var command = input.Substring(0, index); var cmdArgs = input.Substring(index + 1).Split(';'); switch (command) { case "AddProduct": Console.WriteLine(center.AddProduct(cmdArgs[0], decimal.Parse(cmdArgs[1]), cmdArgs[2])); break; case "DeleteProducts": Console.WriteLine( cmdArgs.Length == 1 ? center.DeleteProducts(cmdArgs[0]) : center.DeleteProducts(cmdArgs[0], cmdArgs[1])); break; case "FindProductsByName": Console.Write(center.FindProductsByName(cmdArgs[0])); break; case "FindProductsByProducer": Console.Write(center.FindProductsByProducer(cmdArgs[0])); break; case "FindProductsByPriceRange": Console.Write(center.FindProductsByPriceRange(decimal.Parse(cmdArgs[0]), decimal.Parse(cmdArgs[1]))); break; default: throw new ArgumentException(); } } }
public static void Main() { #if DEBUG Console.SetIn(new StreamReader("../../input.txt")); Debug.Listeners.Add(new ConsoleTraceListener()); #endif var date = DateTime.Now; var separator = new[] { ' ' }; var shoppingCenter = new ShoppingCenter(); foreach (int i in Enumerable.Range(0, int.Parse(Console.ReadLine()))) { var line = Console.ReadLine(); var splitted = line.Split(separator, 2); var name = splitted[0]; var parameters = splitted[1].Split(';'); #if DEBUG Output.AppendLine(); Output.AppendLine(line); #endif switch (name) { case "AddProduct": { var product = new Product( name: parameters[0], price: decimal.Parse(parameters[1]), producer: parameters[2] ); shoppingCenter.AddProduct(product); Output.AppendLine("Product added"); break; } case "FindProductsByName": { var products = shoppingCenter.FindProductsByName(parameters[0]); PrintProducts(products); break; } case "FindProductsByProducer": { var products = shoppingCenter.FindProductsByProducer(parameters[0]); PrintProducts(products); break; } case "FindProductsByPriceRange": { var products = shoppingCenter.FindProductsByPriceRange( min: decimal.Parse(parameters[0]), max: decimal.Parse(parameters[1]) ); PrintProducts(products); break; } case "DeleteProducts": { int deletedCount; switch (parameters.Length) { case 1: deletedCount = shoppingCenter.DeleteProducts( producer: parameters[0] ); break; case 2: deletedCount = shoppingCenter.DeleteProducts( name: parameters[0], producer: parameters[1] ); break; default: throw new ArgumentException("DeleteProducts"); } if (deletedCount == 0) { Output.AppendLine("No products found"); break; } Output.AppendLine(deletedCount + " products deleted"); break; } default: throw new ArgumentException("Invalid command: " + name); } } #if !DEBUG || DEBUG Console.Write(Output); #endif Debug.WriteLine(DateTime.Now - date); }
static void Main() { int commandsNumber = int.Parse(Console.ReadLine()); ShoppingCenter center = new ShoppingCenter(); for (int i = 0; i < commandsNumber; i++) { string line = Console.ReadLine(); int firstSpace = line.IndexOf(" "); string command = line.Substring(0, firstSpace); string[] tokens = line.Substring(firstSpace + 1).Split(';'); switch (command) { case "AddProduct": { string name = tokens[0]; double price = double.Parse(tokens[1]); string producer = tokens[2]; Product p = new Product(name, price, producer); center.Add(p); Console.WriteLine("Product added"); break; } case "DeleteProducts": if (tokens.Length == 1) { int count = center.DeleteProductsByProducer(tokens[0]); if (count == 0) { Console.WriteLine("No products found"); } else { Console.WriteLine(count.ToString() + " products deleted"); } } else { int count = center.DeleteProductsByProducerAndName( tokens[0], tokens[1]); if (count == 0) { Console.WriteLine("No products found"); } else { Console.WriteLine(count.ToString() + " products deleted"); } } break; case "FindProductsByName": List <Product> result = center.FindProductsByName(tokens[0]).ToList(); if (result.Count != 0) { Console.WriteLine(string.Join("\n", result)); } else { Console.WriteLine("No products found"); } break; case "FindProductsByProducer": List <Product> result2 = center.FindProductsByProducer(tokens[0]).ToList(); if (result2.Count != 0) { Console.WriteLine(string.Join("\n", result2)); } else { Console.WriteLine("No products found"); } break; case "FindProductsByPriceRange": IEnumerable <Product> result3 = center.FindProductsByPriceRange( double.Parse(tokens[0]), double.Parse(tokens[1])) .OrderBy(x => x); if (result3.Any()) { Console.WriteLine(string.Join("\n", result3)); } else { Console.WriteLine("No products found"); } break; } } }
static void Main() { int commandsNumber = int.Parse(Console.ReadLine()); ShoppingCenter shoppingCenter = new ShoppingCenter(); for (int i = 0; i < commandsNumber; i++) { string line = Console.ReadLine(); int firstSpace = line.IndexOf(" "); string command = line.Substring(0, firstSpace); string[] tokens = line.Substring(firstSpace + 1).Split(';'); switch (command) { case "AddProduct": string name = tokens[0]; double price = double.Parse(tokens[1]); string producer = tokens[2]; Product p = new Product(name, price, producer); shoppingCenter.Add(p); Console.WriteLine("Product added"); break; case "DeleteProducts": if (tokens.Length == 1) { producer = tokens[0]; int countDeleted = shoppingCenter.DeleteProductsByProducer(producer); if (countDeleted == 0) { Console.WriteLine("No products found"); } else { Console.WriteLine(countDeleted.ToString() + " products deleted"); } } else { name = tokens[0]; producer = tokens[1]; int countDeleted = shoppingCenter.DeleteProductsByProducerAndName(name, producer); if (countDeleted == 0) { Console.WriteLine("No products found"); } else { Console.WriteLine(countDeleted.ToString() + " products deleted"); } } break; case "FindProductsByName": name = tokens[0]; List <Product> result = shoppingCenter.FindProductsByName(name).ToList(); if (result.Count != 0) { Console.WriteLine(string.Join(Environment.NewLine, result)); } else { Console.WriteLine("No products found"); } break; case "FindProductsByProducer": producer = tokens[0]; result = shoppingCenter.FindProductsByProducer(producer).ToList(); if (result.Count != 0) { Console.WriteLine(string.Join(Environment.NewLine, result)); } else { Console.WriteLine("No products found"); } break; case "FindProductsByPriceRange": double priceLow = double.Parse(tokens[0]); double priceHigh = double.Parse(tokens[1]); result = shoppingCenter.FindProductsByPriceRange(priceLow, priceHigh) .ToList(); if (result.Count != 0) { Console.WriteLine(string.Join(Environment.NewLine, result)); } else { Console.WriteLine("No products found"); } break; } } }
public static void Main() { ShoppingCenter shoppingCenter = new ShoppingCenter(); int numberOfCommands = int.Parse(Console.ReadLine()); for (int i = 0; i < numberOfCommands; i++) { string commandLine = Console.ReadLine(); string command = commandLine.Remove(commandLine.IndexOf(' ')); string[] items = commandLine .Substring(command.Length + 1) .Split(';'); switch (command) { case "AddProduct": Product product = new Product(items[0], double.Parse(items[1], CultureInfo.InvariantCulture), items[2]); shoppingCenter.AddProduct(product); Console.WriteLine("Product added"); break; case "DeleteProducts": int count = 0; if (items.Length == 2) { count = shoppingCenter.DeleteProducts(items[0], items[1]); } else if (items.Length == 1) { count = shoppingCenter.DeleteProducts(items[0]); } string resultToPrint = count > 0 ? $"{count} products deleted" : "No products found"; Console.WriteLine(resultToPrint); break; case "FindProductsByName": IEnumerable <Product> findProducts = shoppingCenter .FindProductsByName(items[0]) .ToList(); if (findProducts.Count() == 0) { Console.WriteLine("No products found"); } else { Console.WriteLine(string.Join("\n", findProducts)); } break; case "FindProductsByProducer": IEnumerable <Product> findProductsByProducer = shoppingCenter .FindProductsByProducer(items[0]) .ToList(); if (findProductsByProducer.Count() == 0) { Console.WriteLine("No products found"); } else { Console.WriteLine(string.Join("\n", findProductsByProducer)); } break; case "FindProductsByPriceRange": IEnumerable <Product> findInRange = shoppingCenter.FindProductsByPriceRange( double.Parse(items[0], CultureInfo.InvariantCulture), double.Parse(items[1], CultureInfo.InvariantCulture)) .ToList(); if (findInRange.Count() == 0) { Console.WriteLine("No products found"); } else { Console.WriteLine(string.Join("\n", findInRange)); } break; } } }
public static void Main() { var sc = new ShoppingCenter(); var commands = int.Parse(Console.ReadLine()); for (int i = 0; i < commands; i++) { string line = Console.ReadLine(); int firstSpace = line.IndexOf(" "); string command = line.Substring(0, firstSpace); string[] tokens = line.Substring(firstSpace + 1).Split(';'); switch (command) { case "AddProduct": { string addName = tokens[0]; double addPrice = double.Parse(tokens[1]); string addProducer = tokens[2]; sc.AddProduct(addName, addPrice, addProducer); Console.WriteLine("Product added"); break; } case "DeleteProducts": { int count = 0; if (tokens.Length == 1) { string currProducer = tokens[0]; count = sc.DeleteProductsByProducer(currProducer); } else { string deleteName = tokens[0]; string deleteProducer = tokens[1]; count = sc.DeleteProductsByProducerAndName(deleteName, deleteProducer); } PrintRemoveMessage(count); break; } case "FindProductsByName": { string findByName = tokens[0]; PrintProducts(sc.FindProductsByName(findByName).ToList()); break; } case "FindProductsByProducer": { string findByProd = tokens[0]; PrintProducts(sc.FindProductsByProducer(findByProd).ToList()); break; } case "FindProductsByPriceRange": { double lowerRange = double.Parse(tokens[0]); double upperRange = double.Parse(tokens[1]); PrintProducts(sc.FindProductsByPriceRange(lowerRange, upperRange).OrderBy(x => x).ToList()); break; } } } }
public static void Main() { #if DEBUG Console.SetIn(new StreamReader("../../input.txt")); Debug.Listeners.Add(new ConsoleTraceListener()); #endif var date = DateTime.Now; var separator = new[] { ' ' }; var shoppingCenter = new ShoppingCenter(); foreach (int i in Enumerable.Range(0, int.Parse(Console.ReadLine()))) { var line = Console.ReadLine(); var splitted = line.Split(separator, 2); var name = splitted[0]; var parameters = splitted[1].Split(';'); #if DEBUG Output.AppendLine(); Output.AppendLine(line); #endif switch (name) { case "AddProduct": { var product = new Product( name: parameters[0], price: decimal.Parse(parameters[1]), producer: parameters[2] ); shoppingCenter.AddProduct(product); Output.AppendLine("Product added"); break; } case "FindProductsByName": { var products = shoppingCenter.FindProductsByName(parameters[0]); PrintProducts(products); break; } case "FindProductsByProducer": { var products = shoppingCenter.FindProductsByProducer(parameters[0]); PrintProducts(products); break; } case "FindProductsByPriceRange": { var products = shoppingCenter.FindProductsByPriceRange( min: decimal.Parse(parameters[0]), max: decimal.Parse(parameters[1]) ); PrintProducts(products); break; } case "DeleteProducts": { int deletedCount; switch (parameters.Length) { case 1: deletedCount = shoppingCenter.DeleteProducts( producer: parameters[0] ); break; case 2: deletedCount = shoppingCenter.DeleteProducts( name: parameters[0], producer: parameters[1] ); break; default: throw new ArgumentException("DeleteProducts"); } if (deletedCount == 0) { Output.AppendLine("No products found"); break; } Output.AppendLine(deletedCount + " products deleted"); break; } default: throw new ArgumentException("Invalid command: " + name); } } #if !DEBUG || DEBUG Console.Write(Output); #endif Debug.WriteLine(DateTime.Now - date); }
public static void Main() { int commandsNumber = int.Parse(Console.ReadLine()); ShoppingCenter center = new ShoppingCenter(); for (int i = 0; i < commandsNumber; i++) { string line = Console.ReadLine(); int firstSpace = line.IndexOf(" "); string command = line.Substring(0, firstSpace); string[] args = line.Substring(firstSpace + 1).Split(';'); List <Product> result = new List <Product>(); switch (command) { case "AddProduct": string name = args[0]; double price = double.Parse(args[1]); string producer = args[2]; Product p = new Product(name, price, producer); center.Add(p); Console.WriteLine("Product added"); break; case "DeleteProducts": int count = 0; if (args.Length == 1) // delete producer { count = center.DeleteProductsByProducer(args[0]); } else { count = center.DeleteProductsByProducerAndName( args[0], args[1]); } if (count == 0) { Console.WriteLine("No products found"); } else { Console.WriteLine(count + " products deleted"); } break; case "FindProductsByName": result = center.FindProductsByName(args[0]).ToList(); break; case "FindProductsByProducer": result = center.FindProductsByProducer(args[0]).ToList(); break; case "FindProductsByPriceRange": result = center.FindProductsByPriceRange( double.Parse(args[0]), double.Parse(args[1])) .OrderBy(x => x) .ToList(); break; } if (command.StartsWith("Find")) { if (result.Count != 0) { Console.WriteLine(string.Join("\n", result)); } else { Console.WriteLine("No products found"); } } } }
public static void Main() { ShoppingCenter center = new ShoppingCenter(); int commandsCount = int.Parse(Console.ReadLine()); for (int i = 0; i < commandsCount; i++) { string line = Console.ReadLine(); string command = line.Split(' ').ToArray()[0]; line = line.Substring(line.IndexOf(' ') + 1); switch (command) { case "AddProduct": string[] tokens = line.Split(';').ToArray(); Product p = new Product(tokens[0], double.Parse(tokens[1]), tokens[2]); center.AddProduct(p); Console.WriteLine("Product added"); break; case "FindProductsByName": List <Product> foundByName = center.FindProductsByName(line).ToList(); if (foundByName.Count == 0) { Console.WriteLine("No products found"); } else { Console.WriteLine(string.Join("\n", foundByName)); } break; case "FindProductsByProducer": List <Product> foundByProducer = center.FindProductsByProducer(line).ToList(); if (foundByProducer.Count == 0) { Console.WriteLine("No products found"); } else { Console.WriteLine(string.Join("\n", foundByProducer)); } break; case "FindProductsByPriceRange": string[] prices = line.Split(';').ToArray(); double price1 = double.Parse(prices[0]); double price2 = double.Parse(prices[1]); List <Product> found = center.FindProductsByPriceRange(price1, price2).ToList(); if (found.Count == 0) { Console.WriteLine("No products found"); } else { Console.WriteLine(string.Join("\n", found)); } break; case "DeleteProducts": if (line.Contains(';')) { string[] args = line.Split(';').ToArray(); int deletedProducts = center.DeleteProducts(args[0], args[1]); if (deletedProducts == 0) { Console.WriteLine("No products found"); } else { Console.WriteLine($"{deletedProducts} products deleted"); } } else { int deletedProducts = center.DeleteProducts(line); if (deletedProducts == 0) { Console.WriteLine("No products found"); } else { Console.WriteLine($"{deletedProducts} products deleted"); } } break; } } }
public static void Main() { var shoppingCenter = new ShoppingCenter(); var n = int.Parse(Console.ReadLine()); for (int i = 0; i < n; i++) { var input = Console.ReadLine(); var command = input.Split()[0]; var tokens = input.Replace(command, "").Trim().Split(';'); switch (command) { case "AddProduct": shoppingCenter.AddProduct(tokens[0], decimal.Parse(tokens[1]), tokens[2]); Console.WriteLine("Product added"); break; case "DeleteProducts": var count = 0; if (tokens.Length == 1) { count = shoppingCenter.DeleteProducts(tokens[0]); } else if (tokens.Length == 2) { count = shoppingCenter.DeleteProducts(tokens[0], tokens[1]); } if (count == 0) { Console.WriteLine("No products found"); } else { Console.WriteLine($"{count} products deleted"); } break; case "FindProductsByName": var result = shoppingCenter.FindProductsByName(tokens[0]); if (!result.Any()) { Console.WriteLine("No products found"); } else { Console.WriteLine(string.Join(Environment.NewLine, result)); } break; case "FindProductsByProducer": var result2 = shoppingCenter.FindProductsByProducer(tokens[0]); if (!result2.Any()) { Console.WriteLine("No products found"); } else { Console.WriteLine(string.Join(Environment.NewLine, result2)); } break; case "FindProductsByPriceRange": var result3 = shoppingCenter.FindProductsByPriceRange(decimal.Parse(tokens[0]), decimal.Parse(tokens[1])); if (!result3.Any()) { Console.WriteLine("No products found"); } else { Console.WriteLine(string.Join(Environment.NewLine, result3)); } break; } } }