static void Main(string[] args)
        {
            MyStack <int> myStack = new MyStack <int>();

            string commandInput = Console.ReadLine();

            while (commandInput != "END")
            {
                string[] tokens = commandInput
                                  .Split(new string[] { " ", ", " }, StringSplitOptions.RemoveEmptyEntries);
                string command = tokens[0];

                if (command == "Push")
                {
                    foreach (string item in tokens.Skip(1))
                    {
                        myStack.Push(int.Parse(item));
                    }
                }
                else if (command == "Pop")
                {
                    if (myStack.Count == 0)
                    {
                        Console.WriteLine("No elements");
                    }
                    else
                    {
                        myStack.Pop();
                    }
                }
                commandInput = Console.ReadLine();
            }

            foreach (int i in myStack)
            {
                Console.WriteLine(i);
            }

            foreach (int i in myStack)
            {
                Console.WriteLine(i);
            }
        }
        static void Main(string[] args)
        {
            MyStack <int> myStack = new MyStack <int>();

            string commandInput = Console.ReadLine();

            while (commandInput != "END")
            {
                string[] commandData =
                    commandInput.Split(new string[] { " ", ", " }, StringSplitOptions.RemoveEmptyEntries);

                string command = commandData[0];

                if (command == "Push")
                {
                    for (int i = 1; i < commandData.Length; i++)
                    {
                        int item = int.Parse(commandData[i]);
                        myStack.Push(item);
                    }
                }
                else if (command == "Pop")
                {
                    try
                    {
                        myStack.Pop();
                    }
                    catch (InvalidOperationException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }

                commandInput = Console.ReadLine();
            }

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

            Console.WriteLine(string.Join(Environment.NewLine, myStack));
        }
Пример #3
0
        public static void Main()
        {
            string inputLine = String.Empty;
            var    result    = new MyStack <string>();

            while ((inputLine = Console.ReadLine()) != "END")
            {
                var tokens  = inputLine.Split(new[] { " ", ", " }, StringSplitOptions.RemoveEmptyEntries).ToList();
                var command = tokens[0];

                switch (command)
                {
                case "Push":
                    foreach (var item in tokens.Skip(1))
                    {
                        result.Push(item);
                    }
                    break;

                case "Pop":
                    try
                    {
                        result.Pop();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    break;
                }
            }
            foreach (var res in result)
            {
                Console.WriteLine(res);
            }
            foreach (var res in result)
            {
                Console.WriteLine(res);
            }
        }
Пример #4
0
        static void Main(string[] args)
        {
            MyStack <int> stack = new MyStack <int>();

            string input;

            while ((input = Console.ReadLine()) != "END")
            {
                string[] tokens  = input.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
                string   command = tokens[0];

                switch (command)
                {
                case "Push":
                    int[] items = tokens.Skip(1)
                                  .Select(int.Parse)
                                  .ToArray();
                    stack.Push(items); break;

                case "Pop":
                    if (stack.Size == 0)
                    {
                        Console.WriteLine("No elements");
                    }
                    else
                    {
                        stack.Pop();
                    }
                    break;

                default:
                    break;
                }
            }
            for (int i = 0; i < 2; i++)
            {
                Console.WriteLine(string.Join("\n", stack));
            }
        }
Пример #5
0
        static void Main(string[] args)
        {
            MyStack <int> myStack = new MyStack <int>();


            string commandData = Console.ReadLine();

            while (commandData != "END")
            {
                string[] commandArgs = commandData.Split(new string[] { " ", ", " }, StringSplitOptions.RemoveEmptyEntries);
                string   command     = commandArgs[0];

                if (command == "Push")
                {
                    for (int i = 1; i < commandArgs.Length; i++)
                    {
                        int element = int.Parse(commandArgs[i]);
                        myStack.Push(element);
                    }
                }
                else if (command == "Pop")
                {
                    myStack.Pop();
                }
                commandData = Console.ReadLine();
            }

            foreach (var element in myStack)
            {
                Console.WriteLine(element);
            }
            Console.WriteLine(string.Join(Environment.NewLine, myStack));
            //Console.WriteLine(myStack.Pop());
            //Console.WriteLine(myStack.Pop());
            //Console.WriteLine(myStack.Pop());
            //Console.WriteLine(myStack.Pop());
        }