Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- namespace Lexicon
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, string> words = LoadDictionaryFromFile("words.txt");
- MainMenu(words);
- }
- static void MainMenu(Dictionary<string, string> words)
- {
- bool work = true;
- while (work)
- {
- Console.Clear();
- Console.WriteLine("Введите команду: " +
- "\n1. Толкование слова" +
- "\n2. Вывести все слова" +
- "\n3. Вывести все слова с толкованием" +
- "\n4. Выход");
- switch (Console.ReadLine())
- {
- case "1":
- Console.Write("\nВведите слово без пробелов: ");
- if (TrySearchWord(words, Console.ReadLine(), out string result))
- {
- Console.WriteLine("\n" + result);
- }
- else
- {
- Console.WriteLine("Такого слова не найдено");
- }
- break;
- case "2":
- foreach (string word in OutputAllWords(words))
- {
- Console.WriteLine(word);
- }
- break;
- case "3":
- List<string> allWords = OutputAllThesaurus(words);
- foreach (string word in allWords)
- {
- Console.WriteLine(word);
- }
- break;
- case "4":
- Console.WriteLine("Спасибо, что воспользовались нашим словарем!");
- work = false;
- break;
- default:
- Console.WriteLine("Такой команды не существует!");
- break;
- }
- Console.ReadKey();
- }
- }
- static List<string> OutputAllWords(Dictionary<string, string> words)
- {
- List<string> outputWords = new List<string>();
- foreach (string word in words.Keys)
- {
- outputWords.Add(word);
- }
- return outputWords;
- }
- static List<string> OutputAllThesaurus(Dictionary<string, string> words)
- {
- List<string> output = new List<string>();
- foreach (var word in words)
- {
- output.Add(word.Key + "-" + word.Value);
- }
- return output;
- }
- static bool TrySearchWord(Dictionary<string, string> words, string word, out string result)
- {
- if (words.ContainsKey(word + " "))
- {
- result = word + " -" + words[word + " "];
- return true;
- }
- result = "";
- return false;
- }
- static Dictionary<string, string> LoadDictionaryFromFile(string fileName)
- {
- Dictionary<string, string> words = new Dictionary<string, string>();
- string[] file = File.ReadAllLines(fileName);
- foreach (string line in file)
- {
- string[] word = line.Split(new char[] { '-' });
- words.Add(word[0].ToLower(), word[1].ToLower());
- }
- return words;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement