Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace ConsoleApp14
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, List<string>> wordDef = new Dictionary<string, List<string>>();
- string[] text = Console.ReadLine().Split(" | ").ToArray();
- string[] words = Console.ReadLine().Split(" | ").ToArray();
- string command = Console.ReadLine();
- foreach (var pairs in text)
- {
- string[] wordsAndDefinitions = pairs.Split(": ").ToArray();
- string word = wordsAndDefinitions[0];
- string definition = wordsAndDefinitions[1];
- if (!wordDef.ContainsKey(word))
- {
- wordDef.Add(word, new List<string>());
- wordDef[word].Add(definition);
- }
- else
- {
- wordDef[word].Add(definition);
- }
- }
- if (command == "End")
- {
- foreach (var word in words)
- {
- if (wordDef.ContainsKey(word))
- {
- Console.WriteLine($"{word}");
- foreach (var kvp in wordDef[word].OrderByDescending(x => x.Length))
- {
- Console.WriteLine($" -{kvp}");
- }
- }
- }
- }
- else if (command == "List")
- {
- List<string> onlyWords = wordDef.OrderBy(x => x.Key).Select(x => x.Key).ToList();
- Console.WriteLine(string.Join(" ", onlyWords));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement