Exemple #1
0
        public static void Main()
        {
            var myStack = new MyStack <string>();

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

                if (input[0] == "END")
                {
                    break;
                }

                if (input[0] == "Push")
                {
                    myStack.Push(input);
                }
                try
                {
                    if (input[0] == "Pop")
                    {
                        myStack.Pop();
                    }
                }
                catch (Exception ae)
                {
                    Console.WriteLine(ae.Message);
                }
            }

            for (int i = 0; i < 2; i++)
            {
                foreach (var item in myStack)
                {
                    Console.WriteLine(item);
                }
            }
        }
        static void Main(string[] args)
        {
            string comand = Console.ReadLine();

            int[] elements = comand.Split(new string[] { " ", ", " }, StringSplitOptions.RemoveEmptyEntries)
                             .Select(int.Parse).Skip(1).ToArray();
            MyStack <int> stack = new MyStack <int>(elements);

            while ((comand = Console.ReadLine()) != "END")
            {
                string[] comandArgs = comand.Split();
                if (comandArgs[0] == "Pop")
                {
                    stack.Pop();
                }
                else if (comandArgs[0] == "Push")
                {
                    int element = int.Parse(comandArgs[1]);
                    stack.Push(element);
                }
            }
            Console.WriteLine(string.Join(Environment.NewLine, stack));
            Console.WriteLine(string.Join(Environment.NewLine, stack));
        }