Advertisement
svetlyoek

Untitled

Apr 12th, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace ConsoleApp14
  7. {
  8. class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. Dictionary<string, List<string>> wordDef = new Dictionary<string, List<string>>();
  13. string[] text = Console.ReadLine().Split(" | ").ToArray();
  14. string[] words = Console.ReadLine().Split(" | ").ToArray();
  15. string command = Console.ReadLine();
  16. foreach (var pairs in text)
  17. {
  18. string[] wordsAndDefinitions = pairs.Split(": ").ToArray();
  19. string word = wordsAndDefinitions[0];
  20. string definition = wordsAndDefinitions[1];
  21. if (!wordDef.ContainsKey(word))
  22. {
  23. wordDef.Add(word, new List<string>());
  24. wordDef[word].Add(definition);
  25. }
  26. else
  27. {
  28. wordDef[word].Add(definition);
  29. }
  30. }
  31. if (command == "End")
  32. {
  33. foreach (var word in words)
  34. {
  35. if (wordDef.ContainsKey(word))
  36. {
  37. Console.WriteLine($"{word}");
  38. foreach (var kvp in wordDef[word].OrderByDescending(x => x.Length))
  39. {
  40.  
  41. Console.WriteLine($" -{kvp}");
  42. }
  43.  
  44. }
  45. }
  46. }
  47. else if (command == "List")
  48. {
  49.  
  50. List<string> onlyWords = wordDef.OrderBy(x => x.Key).Select(x => x.Key).ToList();
  51.  
  52. Console.WriteLine(string.Join(" ", onlyWords));
  53.  
  54.  
  55.  
  56. }
  57. }
  58.  
  59. }
  60.  
  61.  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement