loter

Forum Topics

Mar 21st, 2018
150
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.  
  5. namespace Shellbound
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. var topics = new Dictionary<string, List<string>>();
  12. List <string> input = Console.ReadLine().Split(new[] { ' ', ',', '-', '>' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  13.  
  14. while (input[0] != "filter")
  15. {
  16. if (topics.ContainsKey(input[0]) == false)
  17. {
  18. topics[input[0]] = new List<string>();
  19. }
  20.  
  21. for (int i = 1; i < input.Count; i++)
  22. {
  23. if (topics[input[0]].Contains(input[i]) == false)
  24. {
  25. topics[input[0]].Add(input[i]);
  26. }
  27. }
  28.  
  29. input = Console.ReadLine().Split(new[] { ' ', ',', '-', '>' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  30. }
  31.  
  32. List<string> filterWords = Console.ReadLine().Split(',').ToList();
  33.  
  34. foreach (var item in topics)
  35. {
  36. bool isValid = true;
  37.  
  38. for (int i = 1; i < input.Count; i++)
  39. {
  40. for (int j = i - 1; j < filterWords.Count; j++)
  41. {
  42. if (input[i] != filterWords[j])
  43. {
  44. isValid = false;
  45. }
  46. }
  47. }
  48.  
  49. if (isValid == false)
  50. {
  51. topics.Remove(item.Key);
  52. }
  53. }
  54.  
  55. foreach (var item in topics)
  56. {
  57. List<string> result = item.Value.Select(x => "#" + x).ToList();
  58. Console.WriteLine($"{item.Key} | {string.Join(",", result)}");
  59. }
  60. }
  61. }
  62. }
Add Comment
Please, Sign In to add comment