static void Main(string[] args)
        {
            var input   = "";
            var myStack = new CustomStack <string>();

            while ((input = Console.ReadLine()) != "END")
            {
                if (input.StartsWith("Push"))
                {
                    var pushSequence = input.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries)
                                       .Skip(1)
                                       .ToArray();
                    myStack.Push(pushSequence);
                }
                else if (input.StartsWith("Pop"))
                {
                    try
                    {
                        myStack.Pop();
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
            }
            foreach (var element in myStack)
            {
                Console.WriteLine(element);
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            var data = new CustomStack <string>();

            while (true)
            {
                var input = Console.ReadLine();
                if (input == "END")
                {
                    break;
                }

                if (input.Contains("Push"))
                {
                    var elements = input.Split(new string[] { ", ", " " }, StringSplitOptions.RemoveEmptyEntries).Skip(1);

                    foreach (var item in elements)
                    {
                        data.Push(item);
                    }
                }
                else
                {
                    data.Pop();
                }
            }

            for (int i = 0; i < 2; i++)
            {
                foreach (var value in data)
                {
                    Console.WriteLine(value);
                }
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            CustomStack <int> stack = new CustomStack <int>();

            while (true)
            {
                string command = Console.ReadLine();
                if (command == "END")
                {
                    break;
                }

                string[] tokens = command.Split(" ", StringSplitOptions.RemoveEmptyEntries);
                switch (tokens[0])
                {
                case "Push":
                    int[] elements = tokens.Skip(1)
                                     .Select(i => i.Split(',').First())
                                     .Select(int.Parse)
                                     .ToArray();
                    stack.Push(elements);
                    break;

                case "Pop":
                    try
                    {
                        stack.Pop();
                    }
                    catch (InvalidOperationException ioe)
                    {
                        Console.WriteLine(ioe.Message);
                    }
                    break;
                }
            }

            foreach (int number in stack)
            {
                Console.WriteLine(number);
            }

            foreach (int number in stack)
            {
                Console.WriteLine(number);
            }
        }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            string            input  = Console.ReadLine();
            CustomStack <int> cStack = new CustomStack <int>();

            while (input != "END")
            {
                string[] commands = input.Split(" ", StringSplitOptions.RemoveEmptyEntries);
                string   command  = commands[0];
                string[] items    = commands.Skip(1).Select(x => x.TrimEnd(',')).ToArray();

                int[] elementsToAdd = items.Select(int.Parse).ToArray();
                switch (command)
                {
                case "Push":
                    foreach (int item in elementsToAdd)
                    {
                        cStack.Push(item);
                    }
                    break;

                case "Pop":
                    try
                    {
                        cStack.Pop();
                    }
                    catch (InvalidOperationException ioe)
                    {
                        Console.WriteLine(ioe.Message);
                    }
                    break;
                }
                input = Console.ReadLine();
            }

            foreach (var item in cStack)
            {
                Console.WriteLine(item);
            }
            foreach (var item in cStack)
            {
                Console.WriteLine(item);
            }
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            CustomStack <int> stack = new CustomStack <int>();

            string[] input = Console.ReadLine().Split(new char[] { ' ', ',' },
                                                      StringSplitOptions.RemoveEmptyEntries);

            while (input[0] != "END")
            {
                int[] numbers = input.Skip(1).Select(x => int.Parse(x)).ToArray();

                if (input[0] == "Push")
                {
                    for (int i = 1; i < input.Length; i++)
                    {
                        stack.Push(int.Parse(input[i]));
                    }
                }

                else if (input[0] == "Pop")
                {
                    try
                    {
                        stack.Pop();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }

                input = Console.ReadLine().Split();
            }

            foreach (var item in stack)
            {
                Console.WriteLine(item);
            }
            foreach (var item in stack)
            {
                Console.WriteLine(item);
            }
        }
        public static void Main()
        {
            var stack = new CustomStack <int>();

            while (true)
            {
                var command = Console.ReadLine()
                              .Split(new[] { ' ', ',' }
                                     , StringSplitOptions.RemoveEmptyEntries);

                switch (command[0])
                {
                case "Push":
                    var elements = command
                                   .Skip(1)
                                   .Select(int.Parse)
                                   .ToList();

                    stack.Push(elements);
                    break;

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

                case "END":
                    for (int i = 0; i < 2; i++)
                    {
                        foreach (var element in stack)
                        {
                            Console.WriteLine(element);
                        }
                    }

                    return;
                }
            }
        }