Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace forum_topics
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, HashSet<string>> topics = new Dictionary<string, HashSet<string>>();
- string inputline = Console.ReadLine();
- while (inputline != "filter")
- {
- var inputData = inputline.Split(new[] { '-', '>', ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
- var currentKey = inputData[0];
- if (!topics.ContainsKey(currentKey))
- {
- topics[currentKey] = new HashSet<string>();
- }
- for (int i = 1; i < inputData.Length; i++)
- {
- topics[currentKey].Add(inputData[i]);
- }
- inputline = Console.ReadLine();
- }
- var tagSequence = Console.ReadLine().Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
- foreach (var entry in topics)
- {
- bool containsTag = false;
- for (int i = 0; i < tagSequence.Count; i++)
- {
- if (entry.Value.Contains(tagSequence[i]))
- {
- containsTag = true;
- }
- else
- {
- containsTag = false;
- break;
- }
- }
- var topic = entry.Key;
- var tags = entry.Value;
- if (containsTag)
- {
- Console.WriteLine($"{topic} | #{string.Join(", #", tags)}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement