コード例 #1
0
        public static void Main(string[] args)
        {
            SoftuniList <string> softuniList = new SoftuniList <string>();

            string input = Console.ReadLine();

            while (input != "END")
            {
                string[] inputArgs = input.Split();

                string command = inputArgs[0];

                string element = string.Empty;

                switch (command)
                {
                case "Add":
                    element = inputArgs[1];
                    softuniList.Add(element);
                    break;

                case "Remove":
                    int index = int.Parse(inputArgs[1]);
                    softuniList.Remove(index);
                    break;

                case "Contains":
                    element = inputArgs[1];
                    Console.WriteLine(softuniList.Contains(element));
                    break;

                case "Swap":
                    int firstIndex  = int.Parse(inputArgs[1]);
                    int secondIndex = int.Parse(inputArgs[2]);
                    softuniList.Swap(firstIndex, secondIndex);
                    break;

                case "Greater":
                    element = inputArgs[1];
                    Console.WriteLine(softuniList.CountGreaterThan(element));
                    break;

                case "Max":
                    Console.WriteLine(softuniList.Max());
                    break;

                case "Min":
                    Console.WriteLine(softuniList.Min());
                    break;

                case "Print":
                    Console.WriteLine(softuniList);
                    break;

                case "Sort":
                    softuniList.Sort();
                    break;

                default:
                    break;
                }

                input = Console.ReadLine();
            }
        }
コード例 #2
0
ファイル: StartUp.cs プロジェクト: IliaValov/CSharp-OOP
        static void Main(string[] args)
        {
            ISoftuniList <string> softuniList = new SoftuniList <string>();

            string[] input = Console.ReadLine().Split();

            while (input[0] != "END")
            {
                //void Add(T element)
                //T Remove(int index)
                //bool Contains(T element)
                //void Swap(int index1, int index2)
                //int CountGreaterThan(T element)
                //T Max()
                //T Min()



                string command = input[0];

                switch (command)
                {
                case "Add":
                    softuniList.Add(input[1]);
                    break;

                case "Remove":
                    softuniList.Remove(int.Parse(input[1]));
                    break;

                case "Contains":
                    Console.WriteLine(softuniList.Contains(input[1]));
                    break;

                case "Swap":
                    softuniList.Swap(int.Parse(input[1]), int.Parse(input[2]));
                    break;

                case "Greater":
                    Console.WriteLine(softuniList.CountGreaterThan(input[1]));
                    break;

                case "Max":
                    Console.WriteLine(softuniList.Max());
                    break;

                case "Min":
                    Console.WriteLine(softuniList.Min());
                    break;

                case "Sort":
                    softuniList.Sort();
                    break;

                case "Print":
                    foreach (var item in softuniList)
                    {
                        Console.WriteLine(item);
                    }
                    break;

                default:
                    break;
                }


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