Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- class Program
- {
- private const string ExitCommandEng = "exit";
- private const string ExitCommandRus = "выход";
- private const string WarningMessageEmptyInput = "Пустой ввод. Попробуйте снова.";
- private const string ErrorMessageWordNotFound = "Слово \"{0}\" не найдено в словаре.";
- private const string Title = "ENG ⇄ RUS Dictionary";
- private const string InfoMessageProgramEnded = "Программа завершена.";
- private const string StartMessage = "Введите слово(или 'exit'/'выход' для выхода): ";
- private const string BoarderLine = "======================================";
- private const string HeaderTitle = " ENG ⇄ RUS Dictionary ";
- public static void Main()
- {
- Console.Clear();
- Console.OutputEncoding = Encoding.UTF8;
- Console.Title = Title;
- var dictionary = new Dictionary<string, string>
- {
- { "apple", "яблоко" },
- { "book", "книга" },
- { "car", "машина" },
- { "house", "дом" },
- { "computer", "компьютер" }
- };
- PrintHeader();
- bool isRunning = true;
- while (isRunning == true)
- {
- Console.Write(StartMessage);
- string? input = Console.ReadLine();
- if (string.IsNullOrWhiteSpace(input))
- {
- PrintWarning(WarningMessageEmptyInput);
- continue;
- }
- string trimmedInput = input.Trim();
- string normalizedInput = trimmedInput.ToLower();
- if (normalizedInput == ExitCommandEng ||
- normalizedInput == ExitCommandRus)
- {
- isRunning = false;
- PrintInfo(InfoMessageProgramEnded);
- continue;
- }
- if (dictionary.TryGetValue(normalizedInput, out string russianTranslation))
- {
- PrintSuccess($"{trimmedInput} → {russianTranslation}");
- continue;
- }
- bool isFound = false;
- foreach (KeyValuePair<string, string> pair in dictionary)
- {
- if (string.Equals(pair.Value, trimmedInput, StringComparison.OrdinalIgnoreCase))
- {
- PrintSuccess($"{trimmedInput} → {pair.Key}");
- isFound = true;
- break;
- }
- }
- if (isFound == false)
- {
- PrintError(string.Format(ErrorMessageWordNotFound, trimmedInput));
- }
- }
- }
- private static void PrintHeader()
- {
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.WriteLine(BoarderLine);
- Console.WriteLine(HeaderTitle);
- Console.WriteLine(BoarderLine);
- Console.ResetColor();
- Console.WriteLine();
- }
- private static void PrintSuccess(string message)
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine($"✔ {message}");
- Console.ResetColor();
- Console.WriteLine();
- }
- private static void PrintWarning(string message)
- {
- Console.ForegroundColor = ConsoleColor.Yellow;
- Console.WriteLine($"! {message}");
- Console.ResetColor();
- Console.WriteLine();
- }
- private static void PrintError(string message)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine($"✘ {message}");
- Console.ResetColor();
- Console.WriteLine();
- }
- private static void PrintInfo(string message)
- {
- Console.ForegroundColor = ConsoleColor.Cyan;
- Console.WriteLine(message);
- Console.ResetColor();
- Console.WriteLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment