Esempio n. 1
0
        public static void Main()
        {
            var elements = Console.ReadLine()
                           .Split(',', ' ')
                           .Skip(1)
                           .ToArray();

            var customStack = new CustomStack <string>();

            foreach (var element in elements)
            {
                if (element != "")
                {
                    customStack.Push(element);
                }
            }

            string input = String.Empty;

            while ((input = Console.ReadLine()) != "END")
            {
                string command = input.Split(' ')[0];

                if (command == "Pop")
                {
                    try
                    {
                        customStack.Pop();
                    }
                    catch (InvalidOperationException ioex)
                    {
                        Console.WriteLine(ioex.Message);
                    }
                }
                else if (command == "Push")
                {
                    customStack.Push(input.Split(' ')[1]);
                }
            }

            foreach (var element in customStack)
            {
                Console.WriteLine(element);
            }
            foreach (var element in customStack)
            {
                Console.WriteLine(element);
            }
        }
Esempio n. 2
0
        public static void Main()
        {
            CustomStack <string> stack = new CustomStack <string>();

            while (true)
            {
                string input = Console.ReadLine();

                if (input == "END")
                {
                    foreach (var item in stack)
                    {
                        Console.WriteLine(item);
                    }

                    foreach (var item in stack)
                    {
                        Console.WriteLine(item);
                    }

                    break;
                }

                string[] splittedInput = input.Split(" ", 2);

                string command = splittedInput[0];

                if (command == "Push")
                {
                    string[] elementsToPush = splittedInput[1].Split(", ");

                    foreach (var element in elementsToPush)
                    {
                        stack.Push(element);
                    }
                }
                else if (command == "Pop")
                {
                    try
                    {
                        stack.Pop();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            string input = Console.ReadLine();

            CustomStack <int> stack = new CustomStack <int>();

            while (input != "END")
            {
                string[] splitedInput = input.Split(" ", 2);

                string command = splitedInput[0];

                if (command == "Push")
                {
                    int[] numbers = splitedInput[1]
                                    .Split(", ")
                                    .Select(int.Parse)
                                    .ToArray();

                    stack.Push(numbers);
                }
                else
                {
                    try
                    {
                        stack.Pop();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }

                input = Console.ReadLine();
            }

            for (int i = 0; i < 2; i++)
            {
                foreach (var number in stack)
                {
                    Console.WriteLine(number);
                }
            }
        }
        static void Main(string[] args)
        {
            string            command = Console.ReadLine();
            CustomStack <int> stack   = new CustomStack <int>();

            while (command != "END")
            {
                if (command.Contains("Push"))
                {
                    string[] elements = command
                                        .Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries)
                                        .Skip(1)
                                        .ToArray();

                    foreach (var element in elements)
                    {
                        stack.Push(int.Parse(element));
                    }
                }
                else if (command.Contains("Pop"))
                {
                    try
                    {
                        stack.Pop();
                    }
                    catch (Exception exception)
                    {
                        Console.WriteLine(exception.Message);
                    }
                }

                command = Console.ReadLine();
            }

            foreach (var element in stack)
            {
                Console.WriteLine(element);
            }
            foreach (var element in stack)
            {
                Console.WriteLine(element);
            }
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            CustomStack <string> myStack = new CustomStack <string>();

            string[] input = Console.ReadLine().Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
            while (input[0] != "END")
            {
                string cmd = input[0];
                switch (cmd)
                {
                case "Push":
                    for (int i = 1; i < input.Length; i++)
                    {
                        string currElement = input[i];
                        myStack.Push(currElement);
                    }
                    ;
                    break;

                case "Pop":
                    myStack.Pop();
                    break;

                default:
                    break;
                }
                input = Console.ReadLine().Split(new char[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
            }
            foreach (var item in myStack)
            {
                Console.WriteLine(item);
            }
            foreach (var item in myStack)
            {
                Console.WriteLine(item);
            }
        }