Created
January 19, 2025 18:57
-
-
Save Darklega228/562b8ca4363305ece67d800f3b8245eb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Text.RegularExpressions; | |
| /*class OdnoMasiv | |
| { | |
| static void Main() | |
| { | |
| // Ввод числа | |
| Console.Write("Введите число от 0 до 10 000 000: "); | |
| if (int.TryParse(Console.ReadLine(), out int number) && number >= 0 && number <= 10_000_000) | |
| { | |
| // Вывод числа словами | |
| Console.WriteLine($"Число словами: {NumberToWords(number)}"); | |
| } | |
| else | |
| { | |
| Console.WriteLine("Некорректный ввод. Убедитесь, что число в диапазоне от 0 до 10 000 000."); | |
| } | |
| } | |
| static string NumberToWords(int number) | |
| { | |
| if (number == 0) return "ноль"; | |
| var ones = new[] { "", "один", "два", "три", "четыре", "пять", "шесть", "семь", "восемь", "девять" }; | |
| var teens = new[] { "десять", "одиннадцать", "двенадцать", "тринадцать", "четырнадцать", "пятнадцать", "шестнадцать", "семнадцать", "восемнадцать", "девятнадцать" }; | |
| var tens = new[] { "", "", "двадцать", "тридцать", "сорок", "пятьдесят", "шестьдесят", "семьдесят", "восемьдесят", "девяносто" }; | |
| var hundreds = new[] { "", "сто", "двести", "триста", "четыреста", "пятьсот", "шестьсот", "семьсот", "восемьсот", "девятьсот" }; | |
| var result = ""; | |
| if (number >= 1_000_000) | |
| { | |
| int millions = number / 1_000_000; | |
| result += $"{NumberToWords(millions)} миллион{(millions % 10 == 1 && millions % 100 != 11 ? "" : "ов")} "; | |
| number %= 1_000_000; | |
| } | |
| if (number >= 1_000) | |
| { | |
| int thousands = number / 1_000; | |
| result += $"{NumberToWords(thousands)} тысяча{(thousands % 10 == 1 && thousands % 100 != 11 ? "" : "и")} "; | |
| number %= 1_000; | |
| } | |
| if (number >= 100) | |
| { | |
| int h = number / 100; | |
| result += $"{hundreds[h]} "; | |
| number %= 100; | |
| } | |
| if (number >= 20) | |
| { | |
| int t = number / 10; | |
| result += $"{tens[t]} "; | |
| number %= 10; | |
| } | |
| if (number >= 10 && number <= 19) | |
| { | |
| result += $"{teens[number - 10]} "; | |
| } | |
| else if (number > 0) | |
| { | |
| result += $"{ones[number]} "; | |
| } | |
| return result.Trim(); | |
| } | |
| }*/ | |
| /*class Dvumernui | |
| { | |
| static void Main() | |
| { | |
| // Задаем размеры массива | |
| Console.Write("Введите количество строк (N): "); | |
| int n = int.Parse(Console.ReadLine()); | |
| Console.Write("Введите количество столбцов (M): "); | |
| int m = int.Parse(Console.ReadLine()); | |
| int[,] array = new int[n, m]; | |
| FillArray(array, n, m); | |
| PrintArray(array); | |
| } | |
| static void FillArray(int[,] array, int n, int m) | |
| { | |
| int value = 1; | |
| for (int col = 0; col < m; col++) | |
| { | |
| for (int row = 0; row < n; row++) | |
| { | |
| array[row, col] = value; | |
| value++; | |
| } | |
| } | |
| } | |
| static void PrintArray(int[,] array) | |
| { | |
| int rows = array.GetLength(0); | |
| int cols = array.GetLength(1); | |
| for (int i = 0; i < rows; i++) | |
| { | |
| for (int j = 0; j < cols; j++) | |
| { | |
| Console.Write(array[i, j].ToString().PadLeft(4)); | |
| } | |
| Console.WriteLine(); | |
| } | |
| } | |
| // пример N: 4, M: 5 | |
| }*/ | |
| class Stroki | |
| { | |
| static void Main() | |
| { | |
| Console.Write("Введите строку: "); | |
| string input = Console.ReadLine(); | |
| if (IsPalindrome(input)) | |
| { | |
| Console.WriteLine("Строка является палиндромом."); | |
| } | |
| else | |
| { | |
| Console.WriteLine("Строка не является палиндромом."); | |
| } | |
| } | |
| static bool IsPalindrome(string input) | |
| { | |
| // Убираем пробелы, знаки препинания | |
| string cleaned = Regex.Replace(input, "[\\W_]+", "").ToLower(); | |
| // Проверяем, является ли строка палиндромом | |
| int length = cleaned.Length; | |
| for (int i = 0; i < length / 2; i++) | |
| { | |
| if (cleaned[i] != cleaned[length - 1 - i]) | |
| { | |
| return false; | |
| } | |
| } | |
| return true; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment