public static void Task1()
        {
            ServingStaticClass.PrintTaskWelcomeScreen("Вы выбрали задачу создания файла символов\nДавайте начнем:\n");

            string path           = ServingStaticClass.MakeQuestion("имя файла");
            string charStartCode  = ServingStaticClass.MakeQuestion("код начального символа");
            string charFihishCode = ServingStaticClass.MakeQuestion("код конечного символа");

            try
            {
                bool result = CreateCharsFile(path, UInt32.Parse(charStartCode), UInt32.Parse(charFihishCode));
                if (result)
                {
                    ServingStaticClass.Pause("\nЗапись файла завершена.\nНажмите любую клавишу.");
                }
                else
                {
                    ServingStaticClass.Pause("\nОшибка выполнения задачи.\nДля возврата в главное меню нажмите любую клавишу.");
                }
            }
            catch (Exception ex)
            {
                ServingStaticClass.Print($"Что-то пошло не так: {ex.Message}");
                ServingStaticClass.Pause("\nОшибка выполнения задачи.\nДля возврата в главное меню нажмите любую клавишу.");
            }
        }
        private static bool CreateCharsFile(string fileName, uint beginCode, uint finishCode)
        {
            uint bC = beginCode;
            uint fC = finishCode;

            if (beginCode > finishCode)
            {
                bC = finishCode;
                fC = beginCode;
            }

            StreamWriter stream = null;

            try
            {
                stream = new StreamWriter(fileName);
                for (uint currentCode = bC; currentCode <= fC; currentCode++)
                {
                    stream.WriteLine(Convert.ToChar(currentCode));
                }

                stream.Close();

                return(true);
            }
            catch (Exception ex)
            {
                ServingStaticClass.Print($"\nЧто-то пошло не так: {ex.Message}");
                return(false);
            }
        }
Beispiel #3
0
        public static void Task4()
        {
            ServingStaticClass.PrintTaskWelcomeScreen("Вы выбрали задачу проверки является ли одна строка перестановкой другой\nДавайте начнем:\n");

            string userStringA = ServingStaticClass.MakeQuestion("первую строку");
            string userStringB = ServingStaticClass.MakeQuestion("вторую строку");

            //проверка через массив char
            ServingStaticClass.Print("\nПроверка через массив char\n");
            bool result = ShuffleStringsEquels(userStringA, userStringB);

            if (result)
            {
                ServingStaticClass.Print("\nСтроки одинаковы.\n");
            }
            else
            {
                ServingStaticClass.Print("\nСтроки различны.\n");
            }

            //проверка через массив LINQ
            ServingStaticClass.Print("\nПроверка через массив char\n");
            bool result1 = ShuffleStringsEquels(userStringA, userStringB, StringEquelsMethod.LINQ);

            if (result1)
            {
                ServingStaticClass.Print("\nСтроки одинаковы.\n");
            }
            else
            {
                ServingStaticClass.Print("\nСтроки различны.\n");
            }

            ServingStaticClass.Pause("");
        }
Beispiel #4
0
        public static void Task5()
        {
            //решается на словаре и LINQ - массивами не интересно

            ServingStaticClass.PrintTaskWelcomeScreen("Вы выбрали задачу ЕГЭ\nДавайте начнем:\n");

            string path = ServingStaticClass.MakeQuestion("имя файла с оценками студентов");

            Student[] students = ReadStudentsFromFile(path);

            if (students != null)
            {
                //количество разных значений оценок которые нужно вывести
                const int countMinGrades = 3;

                Dictionary <Student, double> listStudents = new Dictionary <Student, double>();

                foreach (Student item in students)
                {
                    listStudents.Add(item, item.AverageGrade());
                }

                //первые 3 (countMinGrades) значения средней оценки
                IEnumerable <double> distinctMinGrades = listStudents.Values.ToArray().Distinct().OrderBy(i => i).Take(countMinGrades);

                foreach (KeyValuePair <Student, double> item in listStudents.OrderBy(key => key.Value))
                {
                    if (distinctMinGrades.Contains(item.Value))
                    {
                        Console.WriteLine($"{item.Key} {item.Value}");
                    }
                    else
                    {
                        break;  // список за пределами нужных значений дальше не интересует
                    }
                }
                ServingStaticClass.Pause("");
            }
            else
            {
                ServingStaticClass.Pause("\nОшибка выполнения.\nДля перехода в главное меню нажмите любую клавишу.");
            }
        }
Beispiel #5
0
        private static Student[] ReadStudentsFromFile(string filename)
        {
            string[] allStudentsTxt = null;

            try
            {
                allStudentsTxt = File.ReadAllLines(filename);
            }
            catch (Exception ex)
            {
                ServingStaticClass.Print($"\nЧто-то пошло не так: {ex.Message}");
                return(null);
            }

            Student[] students = new Student[allStudentsTxt.Length];

            for (int i = 0; i < allStudentsTxt.Length; i++)
            {
                int[] arrayGrades;

                string[] currentStudentData = allStudentsTxt[i].Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                if (currentStudentData.Length > 2)
                {
                    ushort counter = 0;
                    arrayGrades = new int[currentStudentData.Length - 2];
                    for (int countGrades = 2; countGrades < currentStudentData.Length; countGrades++)
                    {
                        arrayGrades[counter] = Int32.Parse(currentStudentData[countGrades]);
                        counter++;
                    }
                }
                else
                {
                    arrayGrades = new int[] { 0 };
                }
                students[i] = new Student(currentStudentData[0], currentStudentData[1], arrayGrades);
            }
            return(students);
        }
        public static void Task2()
        {
            ServingStaticClass.PrintTaskWelcomeScreen("Вы выбрали задачу проверки пароля\nДавайте начнем:\n");

            string userPassword = ServingStaticClass.MakeQuestion("пароль");

            // без регулярок
            ServingStaticClass.Print("\nПроверка пароля без импользования механизма регулярных выражений:");

            bool verificationResult = PasswordVerification(userPassword, out string errorMessage);

            if (verificationResult)
            {
                ServingStaticClass.Print("Проверка пароля успешна!");
            }
            else
            {
                ServingStaticClass.Print($"Предложенный пароль не подходит.\nОписание ошибки: {errorMessage}");
            }

            //регулярки
            ServingStaticClass.Print("\nПроверка пароля с импользованием механизма регулярных выражений:\n");

            bool verificationResult1 = PasswordVerification(userPassword, out string errorMessage1, RegExpUse.UseRegExp);

            if (verificationResult1)
            {
                ServingStaticClass.Print("Проверка пароля успешна!\n");
            }
            else
            {
                ServingStaticClass.Print($"Предложенный пароль не подходит.\n");
            }

            ServingStaticClass.Pause("");
        }