示例#1
0
        private static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            ShoppingCenter shoppingCenter = new ShoppingCenter();
            int            commandsCount  = int.Parse(Console.ReadLine());
            int            index          = 1;

            while (index <= commandsCount)
            {
                string input      = Console.ReadLine();
                int    spaceIndex = input.IndexOf(' ');
                if (spaceIndex == -1)
                {
                    continue;
                }

                string        command   = input.Substring(0, spaceIndex);
                string        paramsStr = input.Substring(spaceIndex + 1);
                string[]      cmdParams = paramsStr.Split(';');
                List <string> commands  = new List <string>();
                commands.Add(command);
                for (int i = 0; i < cmdParams.Length; i++)
                {
                    commands.Add(cmdParams[i]);
                }

                shoppingCenter.ExecuteCommands(commands);
                index++;
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            int            n        = int.Parse(Console.ReadLine());
            string         input    = string.Empty;
            string         name     = string.Empty;
            string         price    = string.Empty;
            string         producer = string.Empty;
            ShoppingCenter center   = new ShoppingCenter();

            for (int line = 0; line < n; line++)
            {
                input = Console.ReadLine();
                List <string> arguments = input.Split(' ').ToList();
                string        command   = arguments[0];
                arguments.RemoveAt(0);
                string data = string.Join(" ", arguments);


                switch (command)
                {
                case "AddProduct":
                    string[] argsToPass = data.Split(';');
                    center.Add(argsToPass[0], argsToPass[1], argsToPass[2]);
                    break;

                case "FindProductsByName":
                    center.FindProductsByName(data);
                    break;

                case "FindProductsByProducer":
                    center.FindProductsByProducer(data);
                    break;

                case "DeleteProducts":
                    argsToPass = data.Split(';');
                    if (argsToPass.Length == 1)
                    {
                        center.DeleteProducts(argsToPass[0]);
                    }
                    else
                    {
                        center.DeleteProducts(argsToPass[0], argsToPass[1]);
                    }
                    break;

                case "FindProductsByPriceRange":
                    argsToPass = data.Split(';');
                    center.FindProductsByPriceRange(argsToPass[0], argsToPass[1]);
                    break;
                }
            }

            Console.ReadLine();
        }
示例#3
0
        public static void Main()
        {
            ShoppingCenter shoppingCenter = new ShoppingCenter();
            int            commandsCount  = int.Parse(Console.ReadLine());

            for (int i = 0; i < commandsCount; i++)
            {
                string commandLine = Console.ReadLine();

                Console.WriteLine(shoppingCenter.ProcessCommand(commandLine));
            }
        }
 public static void Main()
 {
     var shoppinCenter = new ShoppingCenter();
     int numberOfLines = int.Parse(Console.ReadLine());
     for (int i = 0; i < numberOfLines; i++)
     {
         string commandLine = Console.ReadLine();
         string output = shoppinCenter.ProcessCommand(commandLine);
         Console.WriteLine(output);
         Console.WriteLine();
     }
 }
示例#5
0
        public static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            var center = new ShoppingCenter();

            int commands = int.Parse(Console.ReadLine());
            for (int i = 1; i <= commands; i++)
            {
                string command = Console.ReadLine();
                string commandResult = center.ProcessCommand(command);
                Console.WriteLine(commandResult);
            }
        }
示例#6
0
        public static void Main(string[] args)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            var center = new ShoppingCenter();

            int commands = int.Parse(Console.ReadLine());

            for (int i = 1; i <= commands; i++)
            {
                string command       = Console.ReadLine();
                string commandResult = center.ProcessCommand(command);
                Console.WriteLine(commandResult);
            }
        }
        public static void Main()
        {
            var center = new ShoppingCenter();
            int n      = int.Parse(Console.ReadLine());

            var result = new StringBuilder();

            for (int i = 0; i < n; i++)
            {
                var line        = Console.ReadLine().Split(' ').ToList();
                var commandName = line[0];

                line.RemoveAt(0);
                var args = string.Join(" ", line).Split(';');

                if (commandName == "AddProduct")
                {
                    result.AppendLine(center.Add(args[0], decimal.Parse(args[1]), args[2]));
                }
                else if (commandName == "DeleteProducts")
                {
                    if (args.Length == 2)
                    {
                        result.AppendLine(center.DeleteProducts(args[0], args[1]));
                    }
                    else
                    {
                        result.AppendLine(center.DeleteProducts(args[0]));
                    }
                }
                else if (commandName == "FindProductsByName")
                {
                    result.AppendLine(center.FindProductsByName(args[0]));
                }
                else if (commandName == "FindProductsByPriceRange")
                {
                    result.AppendLine(center.FindProductsByPriceRange(decimal.Parse(args[0]), decimal.Parse(args[1])));
                }
                else if (commandName == "FindProductsByProducer")
                {
                    result.AppendLine(center.FindProductsByProducer(args[0]));
                }
            }

            Console.WriteLine(result.ToString().Trim());
        }
示例#8
0
        public static void Main()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

            ShoppingCenter center = new ShoppingCenter();

            StringBuilder answer = new StringBuilder();

            int commands = int.Parse(Console.ReadLine());

            for (int i = 1; i <= commands; i++)
            {
                string command       = Console.ReadLine();
                string commandResult = center.ProcessCommand(command);
                answer.AppendLine(commandResult);
            }

            Console.Write(answer);
        }
示例#9
0
        static void Main()
        {
            ShoppingCenter center = new ShoppingCenter();

            Type type = center.GetType();

            int    numberOfCommands = int.Parse(Console.ReadLine());
            string commandLine      = "";
            string methodName       = "";
            string commandArguments = "";

            MethodInfo[] method;
            for (int i = 0; i < numberOfCommands; i++)
            {
                commandLine = Console.ReadLine();
                int whitespaceIndex = commandLine.IndexOf(" ");
                methodName = commandLine.Substring(0, whitespaceIndex);
                method     = type.GetMethods();
                var      restOfString = commandLine.Substring(whitespaceIndex + 1, commandLine.Length - whitespaceIndex - 1);
                object[] arguments    = SplitArguments(restOfString);
                method.First(m => m.Name == methodName && m.GetParameters().Length == arguments.Length).Invoke(center, arguments);
            }
        }
        static void Main(string[] args)
        {
            int totalCommands = int.Parse(Console.ReadLine());

            var shoppingCenter = new ShoppingCenter();

            for (int i = 0; i < totalCommands; i++)
            {
                string[] commandLine = Console.ReadLine().Split(new char[] { ' ' }, 2);

                string[] parameters = commandLine[1].Split(';');

                switch (commandLine[0])
                {
                case "AddProduct":
                {
                    shoppingCenter.AddProduct(new Product(
                                                  name: parameters[0],
                                                  price: double.Parse(parameters[1]),
                                                  producer: parameters[2])
                                              );

                    result.AppendLine("Product added");
                    break;
                }

                case "DeleteProducts":
                {
                    int deletedCount = 0;

                    switch (parameters.Length)
                    {
                    case 1:
                    {
                        deletedCount = shoppingCenter.DeleteProducts(parameters[0]);
                        break;
                    }

                    case 2:
                    {
                        deletedCount = shoppingCenter.DeleteProducts(parameters[0], parameters[1]);
                        break;
                    }

                    default:
                        throw new ArgumentException("Invalid Delete Parameters");
                    }

                    if (deletedCount == 0)
                    {
                        result.AppendLine("No products found");
                        break;
                    }

                    result.AppendLine(string.Format("{0} products deleted", deletedCount));
                    break;
                }

                case "FindProductsByName":
                {
                    PrintProducts(shoppingCenter.FindProductsByName(parameters[0]));
                    break;
                }

                case "FindProductsByPriceRange":
                {
                    PrintProducts(shoppingCenter.FindProductsByPriceRange(
                                      min: double.Parse(parameters[0]),
                                      max: double.Parse(parameters[1])));
                    break;
                }

                case "FindProductsByProducer":
                {
                    PrintProducts(shoppingCenter.FindProductsByProducer(parameters[0]));
                    break;
                }

                default:
                    throw new ArgumentException("Invalid command!");
                }
            }

            Console.WriteLine(result.ToString().Trim());
        }
示例#11
0
        public static void Main()
        {
            ShoppingCenter shoppingCenter = new ShoppingCenter();

            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                string   line      = Console.ReadLine();
                int      index     = line.IndexOf(' ');
                string   command   = line.Substring(0, index);
                string[] arguments = line.Substring(index + 1).Split(';');

                switch (command)
                {
                case "AddProduct":
                {
                    Product product = new Product(arguments[0], arguments[2], double.Parse(arguments[1]));
                    shoppingCenter.Add(product);
                    Console.WriteLine("Product added");
                }
                break;

                case "DeleteProducts":
                {
                    int count = arguments.Length == 1
                                ? shoppingCenter.DeleteByProducer(arguments[0])
                                : shoppingCenter.DeleteByNameAndProducer(arguments[0], arguments[1]);

                    if (count == 0)
                    {
                        Console.WriteLine("No products found");
                    }
                    else
                    {
                        Console.WriteLine($"{count} products deleted");
                    }
                }
                break;

                case "FindProductsByName":
                {
                    var products = shoppingCenter.FindByName(arguments[0]);
                    PrintProducts(products);
                }
                break;

                case "FindProductsByProducer":
                {
                    var products = shoppingCenter.FindByProducer(arguments[0]);
                    PrintProducts(products);
                }
                break;

                case "FindProductsByPriceRange":
                {
                    double from     = double.Parse(arguments[0]);
                    double to       = double.Parse(arguments[1]);
                    var    products = shoppingCenter.FindByPriceRange(from, to);
                    PrintProducts(products);
                }
                break;
                }
            }
        }
        private void ExecuteTest(string inputFileName, string outputFileName)
        {
            var shoppingCenter = new ShoppingCenter();
            var inputCommands = File.ReadAllLines(@"..\..\..\Judge-Tests\" + inputFileName);
            var output = new StringBuilder();
            int commandsCount = int.Parse(inputCommands[0]);
            for (int i = 1; i <= commandsCount; i++)
            {
                string command = inputCommands[i];
                if (!string.IsNullOrEmpty(command))
                {
                    var commandOutput = shoppingCenter.ProcessCommand(command);
                    output.AppendLine(commandOutput);
                }
            }
            var expectedOutput = File.ReadAllText(@"..\..\..\Judge-Tests\" + outputFileName);
            var actualOutput = output.ToString();

            Assert.AreEqual(expectedOutput, actualOutput);
        }
示例#13
0
 public Engine()
 {
     shoppingCenter = new ShoppingCenter();
 }