Untitled
unknown
plain_text
a year ago
5.6 kB
9
Indexable
using System; using System.Linq; class Program { static string[] names = new string[] { "Айдана", "Айжан", "Айнур", "Алина", "Алишер", }; static string[] kazakhNames = new string[] { "Асылхан", "Әділхан", "Мерей", "Айгерім", "Нұрсұлтан", "Жансая", "Төлеген", "Жанбота", "Динара", "Данияр", "Айдар", "Сауле", "Алия", "Темірлан", "Мәдина", "Айгүл", "Асем", "Жанар", "Жандос", "Гүлшат", "Айна", "Айбар", "Аружан", "Айша", "Бекзат", "Айсулу", "Айсана", "Жанерке", "Айсара", }; static void Main(string[] args) { Console.WriteLine("Добро пожаловать в Рандомайзер"); Console.WriteLine("############################"); Console.WriteLine(); while (true) { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Меню:"); Console.WriteLine("1. Показать все имена"); Console.WriteLine("2. Добавить имена"); Console.WriteLine("3. Создать случайное имя и добавить"); Console.WriteLine("4. Разделить на случайные команды"); Console.WriteLine("5. Выход"); Console.Write("Выберите опцию: "); Console.ResetColor(); string choice = Console.ReadLine(); Console.WriteLine(); switch (choice) { case "1": ShowNames(); break; case "2": AddNames(); break; case "3": GenerateRandomNameAndAdd(); break; case "4": DivideIntoRandomTeams(); break; case "5": Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("До свидания!"); Console.ResetColor(); return; default: Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Выберите корректный вариант."); Console.ResetColor(); break; } Console.WriteLine(); } } static void ShowNames() { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Список имен:"); Console.ResetColor(); foreach (string name in names) { Console.WriteLine(name); } } static void AddNames() { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Введите новые имена через пробел (для завершения нажмите Enter): "); Console.ResetColor(); string input = Console.ReadLine(); string[] newNames = input.Split(' '); foreach (string newName in newNames) { Array.Resize(ref names, names.Length + 1); names[names.Length - 1] = newName; } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Имена успешно добавлены."); Console.ResetColor(); } static void GenerateRandomNameAndAdd() { Random random = new Random(); string randomName = kazakhNames[random.Next(kazakhNames.Length)]; Array.Resize(ref names, names.Length + 1); names[names.Length - 1] = randomName; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine($"Случайное имя '{randomName}' добавлено."); Console.ResetColor(); } static void DivideIntoRandomTeams() { Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("Введите количество участников в команде:"); Console.ResetColor(); int teamSize; while (!int.TryParse(Console.ReadLine(), out teamSize) || teamSize <= 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Введите корректное количество участников в команде (целое положительное число):"); Console.ResetColor(); } Random random = new Random(); string[] shuffledNames = names.OrderBy(x => random.Next()).ToArray(); int teamCount = (int)Math.Ceiling((double)shuffledNames.Length / teamSize); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("\nСоставлены команды:"); Console.ResetColor(); for (int i = 0; i < teamCount; i++) { var team = shuffledNames.Skip(i * teamSize).Take(teamSize); Console.WriteLine($"Команда {i + 1}: {string.Join(", ", team)}"); } } }
Editor is loading...
Leave a Comment