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 forumTopic
- {
- class forumTopic
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- Dictionary<string, List<string>> topicTags = new Dictionary<string, List<string>>();
- while(input != "filter")
- {
- string[] currentInput = input.Split(new string[] { " -> ", ", " }, StringSplitOptions.RemoveEmptyEntries);
- string topic = currentInput[0];
- if (!topicTags.ContainsKey(topic))
- {
- topicTags.Add(topic, new List<string>());
- }
- for (int i = 1; i < currentInput.Length; i++)
- {
- if (!topicTags[topic].Contains(currentInput[i]))
- {
- topicTags[topic].Add(currentInput[i]);
- }
- }
- input = Console.ReadLine();
- }
- List<string> searchedTags = Console.ReadLine().Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries).ToList();
- foreach(KeyValuePair<string,List<string>> subject in topicTags)
- {
- string topic = subject.Key;
- List<string> tag = subject.Value;
- if (IsContained(searchedTags, tag))
- {
- Console.WriteLine($"{topic} | #{string.Join(", #",tag)}");
- }
- }
- }
- static bool IsContained(List<string> searchedTags, List<string> tag)
- {
- bool isContained = false;
- List<string> newtags = new List<string>();
- for (int i = 0; i < searchedTags.Count; i++)
- {
- for (int j = 0; j < tag.Count; j++)
- {
- if (searchedTags[i] == tag[j])
- {
- newtags.Add(searchedTags[i]);
- break;
- }
- }
- }
- searchedTags.Sort();
- newtags.Sort();
- if (searchedTags.SequenceEqual(newtags))
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement