コード例 #1
0
ファイル: StartUp.cs プロジェクト: q2kPetrov/SoftUni-Courses
        static void Main(string[] args)
        {
            var customStack = new CustomStack <int>();
            var input       = Console.ReadLine();

            while (input != "END")
            {
                var arr = input.Split(" ", 2);

                var stringCommand = arr[0];

                if (stringCommand == "Push")
                {
                    var numbers = arr[1].Split(", ").Select(int.Parse).ToArray();
                    customStack.Push(numbers);
                }
                else
                {
                    try
                    {
                        customStack.Pop();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }

                input = Console.ReadLine();
            }

            for (int i = 0; i < 2; i++)
            {
                foreach (var g in customStack)
                {
                    Console.WriteLine(g);
                }
            }
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            string            line        = Console.ReadLine();
            CustomStack <int> customStack = new CustomStack <int>();

            while (line != "END")
            {
                string[] input = line
                                 .Split(new string[] { ", ", " " }, StringSplitOptions.RemoveEmptyEntries)
                                 .ToArray();

                string command = input[0];
                try
                {
                    switch (command)
                    {
                    case "Push":
                        customStack.Push(input.Skip(1).Select(int.Parse).ToList());
                        break;

                    case "Pop":
                        customStack.Pop();
                        break;
                    }
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }

                line = Console.ReadLine();
            }

            for (int i = 0; i < 2; i++)
            {
                Console.WriteLine(string.Join(Environment.NewLine, customStack));
            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            //Console.WriteLine(ReverseString("abcd"));
            //Console.WriteLine(BalancedExpression("ab{<>}cd"));

            var customStack = new CustomStack(5);

            Console.WriteLine($"IsEmpty?: {customStack.IsEmpty()}");

            customStack.Push(5);
            customStack.Push(10);
            customStack.Push(15);
            Console.WriteLine("Before Pop: ");
            customStack.Print();

            Console.WriteLine($"Pop triggered: {customStack.Pop()}");

            Console.WriteLine("After Pop: ");
            customStack.Print();

            Console.WriteLine($"Peek triggered: {customStack.Peek()}");
            Console.WriteLine($"IsEmpty?: {customStack.IsEmpty()}");
        }
コード例 #4
0
        public static void Main()
        {
            string[]             input      = Console.ReadLine().Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
            CustomStack <string> collection = new CustomStack <string>();

            while (input[0] != "END")
            {
                if (input[0] == "Push")
                {
                    collection.Push(input.Skip(1).ToArray());
                }
                else if (input[0] == "Pop")
                {
                    try
                    {
                        collection.Pop();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }

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

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

            foreach (var item in collection)
            {
                Console.WriteLine(item);
            }
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: NUT82/SoftUni-HomeWorks
        static void Main(string[] args)
        {
            CustomStack <int> customStack = new CustomStack <int>();

            string input = Console.ReadLine();

            while (input != "END")
            {
                if (input == "Pop")
                {
                    try
                    {
                        customStack.Pop();
                    }
                    catch (IndexOutOfRangeException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else
                {
                    customStack.Push(input.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries)
                                     .Skip(1)
                                     .Select(int.Parse)
                                     .ToArray());
                }
                input = Console.ReadLine();
            }
            for (int i = 0; i < 2; i++)
            {
                foreach (var item in customStack)
                {
                    Console.WriteLine(item);
                }
            }
        }
コード例 #6
0
        static void Main(string[] args)
        {
            var customStack = new CustomStack <string>();

            while (true)
            {
                var input = Console.ReadLine().Split(new [] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
                switch (input[0])
                {
                case "Push":
                    customStack.Push(input.Skip(1).ToArray());
                    break;

                case "Pop":
                    try
                    {
                        customStack.Pop();
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                    break;

                case "END":
                    for (int i = 0; i < 2; i++)
                    {
                        foreach (var item in customStack)
                        {
                            Console.WriteLine(item);
                        }
                    }
                    return;
                }
            }
        }
コード例 #7
0
ファイル: Program.cs プロジェクト: radoslavBachurov/SoftUni
        static void Main(string[] args)
        {
            CustomStack mystack = new CustomStack();
            string      command = string.Empty;

            while ((command = Console.ReadLine()) != "END")
            {
                if (command == "Pop")
                {
                    try
                    {
                        mystack.Pop();
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("No elements");
                    }
                }
                else
                {
                    int[] commandArr = command.Split(new string[] { ", ", " " }, StringSplitOptions.RemoveEmptyEntries)
                                       .Skip(1).Select(int.Parse).ToArray();
                    mystack.Push(commandArr);
                }
            }

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

            foreach (var item in mystack)
            {
                Console.WriteLine(item);
            }
        }
コード例 #8
0
        public static void Main(string[] args)
        {
            CustomStack <int> stack = new CustomStack <int>();

            string input = string.Empty;

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

                string command = tokens[0];

                if (command == "Push")
                {
                    for (int currentNumber = 1; currentNumber < tokens.Length; currentNumber++)
                    {
                        stack.Push(int.Parse(tokens[currentNumber]));
                    }
                }
                else if (command == "Pop")
                {
                    stack.Pop();
                }
            }

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

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