Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace DEMO_Exam_Dictionary
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] wordAndExplain = Console.ReadLine().Split(" | ").ToArray();
- string command = string.Empty;
- var words = new Dictionary<string, List<string>>();
- if ((command = Console.ReadLine()) == "End") return;
- for (int i = 0; i < wordAndExplain.Length; i++)
- {
- string[] wordAndDefinition = wordAndExplain[i].Split(": ").ToArray();
- string wordName = wordAndExplain[0];
- string wordExplain = wordAndExplain[1];
- if (!words.ContainsKey(wordName))
- {
- words.Add(wordName, new List<string>());
- }
- else words[wordName].Add(wordExplain);
- }
- if ((command = Console.ReadLine()) == "List")
- {
- foreach (var word in words.OrderByDescending(x => x))
- {
- Console.WriteLine($"{word.Key}:");
- foreach (var item in words.OrderBy(x => x))
- {
- Console.WriteLine($" -{string.Join(" ", item)}");
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment