Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class Program
  6. {
  7. static void Main()
  8. {
  9. string keyFromUser = Console.ReadLine();
  10. string valueFromUser = Console.ReadLine();
  11. int lines = int.Parse(Console.ReadLine());
  12. var dict = new Dictionary<string, List<string>>();
  13.  
  14. for (int i = 0; i < lines; i++)
  15. {
  16. string[] tokens = Console.ReadLine().Split(new string[] { " => " }, StringSplitOptions.RemoveEmptyEntries);
  17. string key = tokens[0];
  18. string[] value = tokens[1].Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
  19.  
  20. if (key.Contains(keyFromUser))
  21. {
  22. if (!dict.ContainsKey(key))
  23. {
  24. dict.Add(key, new List<string>());
  25. }
  26.  
  27. foreach (var item in value)
  28. {
  29. if (valueFromUser.Contains(item) || item.Contains(valueFromUser))
  30. {
  31. dict[key].Add(item);
  32. }
  33. }
  34. }
  35. }
  36. foreach (var item in dict)
  37. {
  38. string keyBase = item.Key;
  39. Console.WriteLine($"{keyBase}:");
  40. foreach (var token in item.Value)
  41. {
  42. Console.WriteLine($"-{token}");
  43. }
  44. }
  45.  
  46. }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement