Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _01._Dictionary
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] inputData = Console.ReadLine().Split(" | ", StringSplitOptions.RemoveEmptyEntries).ToArray();
- Dictionary<string, List<string>> wordDefinitions = new Dictionary<string, List<string>>();
- for (int i = 0; i < inputData.Length; i++)
- {
- string[] currentWordDef = inputData[i].Split(": ", StringSplitOptions.RemoveEmptyEntries).ToArray();
- string word = currentWordDef[0];
- string definition = currentWordDef[1];
- if (!wordDefinitions.ContainsKey(word))
- {
- List<string> currDef = new List<string>();
- currDef.Add(definition);
- wordDefinitions.Add(word, currDef);
- }
- else
- {
- wordDefinitions[word].Add(definition);
- }
- }
- string[] wordsToPrint = Console.ReadLine().Split(" | ").ToArray();
- for (int i = 0; i < wordsToPrint.Length; i++)
- {
- string word = wordsToPrint[i];
- if (wordDefinitions.ContainsKey(word))
- {
- Console.WriteLine(word);
- foreach (var definition in wordDefinitions[word].OrderByDescending(x => x.Length))
- {
- Console.WriteLine($" -{definition}");
- }
- }
- }
- string command = Console.ReadLine();
- if (command == "List")
- {
- foreach (var word in wordDefinitions.Keys.OrderBy(x => x))
- {
- Console.Write(word + " ");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement