Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //06. Forum Topics
- var topicsDict = new Dictionary<string, HashSet<string>>();
- string input = Console.ReadLine();
- while (input != "filter")
- {
- string[] inArr = input
- .Split(new string[] { " -> " }, StringSplitOptions.None);
- string topic = inArr[0];
- if (!topicsDict.ContainsKey(topic))
- {
- topicsDict.Add(topic, new HashSet<string>());
- }
- string[] tagsArr = inArr[1]
- .Split(new string[] { ", " }, StringSplitOptions.None);
- foreach (string tag in tagsArr)
- {
- topicsDict[topic].Add(tag);
- }
- input = Console.ReadLine();
- }
- string[] tagsToFind = Console.ReadLine()
- .Split(new string[] { ", " }, StringSplitOptions.None);
- foreach (var item in topicsDict)
- {
- bool tagsToFindAreContained = tagsToFind.All(t => item.Value.Contains(t));
- //bool tagsToFindAreContained = true;
- //foreach (string tag in tagsToFind)
- //{
- // if (!item.Value.Contains(tag))
- // {
- // tagsToFindAreContained = false;
- // break;
- // }
- //}
- if (tagsToFindAreContained)
- {
- var resultList = item.Value.Select(x => "#" + x).ToList();
- Console.WriteLine("{0} | {1}",
- item.Key,
- string.Join(", ", resultList));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement