Advertisement
GabrielDas

Untitled

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