Advertisement
valkata

Untitled

Jul 10th, 2017
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace forumTopic
  8. {
  9.     class forumTopic
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string input = Console.ReadLine();
  14.             Dictionary<string, List<string>> topicTags = new Dictionary<string, List<string>>();
  15.             while(input != "filter")
  16.             {
  17.                 string[] currentInput = input.Split(new string[] { " -> ", ", " }, StringSplitOptions.RemoveEmptyEntries);
  18.                 string topic = currentInput[0];
  19.  
  20.                 if (!topicTags.ContainsKey(topic))
  21.                 {
  22.                     topicTags.Add(topic, new List<string>());
  23.                 }
  24.                
  25.                 for (int i = 1; i < currentInput.Length; i++)
  26.                 {
  27.                     if (!topicTags[topic].Contains(currentInput[i]))
  28.                     {
  29.                         topicTags[topic].Add(currentInput[i]);
  30.                     }
  31.                 }              
  32.  
  33.                 input = Console.ReadLine();
  34.             }
  35.  
  36.             List<string> searchedTags = Console.ReadLine().Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries).ToList();
  37.             foreach(KeyValuePair<string,List<string>> subject in topicTags)
  38.             {
  39.                 string topic = subject.Key;
  40.                 List<string> tag = subject.Value;
  41.                 if (IsContained(searchedTags, tag))
  42.                 {
  43.                     Console.WriteLine($"{topic} | #{string.Join(", #",tag)}");
  44.                 }
  45.  
  46.             }
  47.         }
  48.  
  49.         static bool IsContained(List<string> searchedTags, List<string> tag)
  50.         {
  51.             bool isContained = false;
  52.             List<string> newtags = new List<string>();
  53.             for (int i = 0; i < searchedTags.Count; i++)
  54.             {
  55.                 for (int j = 0; j < tag.Count; j++)
  56.                 {
  57.                     if (searchedTags[i] == tag[j])
  58.                     {
  59.                         newtags.Add(searchedTags[i]);
  60.                         break;
  61.                     }
  62.  
  63.                 }
  64.             }
  65.             searchedTags.Sort();
  66.             newtags.Sort();
  67.  
  68.             if (searchedTags.SequenceEqual(newtags))
  69.             {
  70.                 return true;
  71.             }
  72.             else
  73.             {
  74.                 return false;
  75.             }
  76.         }
  77.     }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement