Advertisement
kalin_markoff

ForumTopics

Mar 19th, 2017
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class ForumTopics
  6. {
  7.     static void Main()
  8.     {
  9.         var topicList = new Dictionary<string, HashSet<string>>();
  10.  
  11.         while (true)
  12.         {
  13.             var input = Console.ReadLine().Split(", ->".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToArray();
  14.             if (input[0] == "filter")
  15.             {
  16.                 break;
  17.             }
  18.  
  19.             var topic = input[0];
  20.  
  21.             if (!topicList.ContainsKey(topic))
  22.             {
  23.                 topicList[topic] = new HashSet<string>();
  24.             }
  25.  
  26.             for (int i = 1; i < input.Length; i++)
  27.             {
  28.                 topicList[topic].Add(input[i]);
  29.             }
  30.         }
  31.  
  32.         var seqenceOfTags = Console.ReadLine().Split(", ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToArray();
  33.        
  34.         foreach (var item in topicList)
  35.         {
  36.             var hasContain = false;
  37.             for (int i = 0; i < seqenceOfTags.Length; i++)
  38.             {
  39.                 if (item.Value.Contains(seqenceOfTags[i]))
  40.                 {
  41.                     hasContain = true;
  42.                 }
  43.                 else
  44.                 {
  45.                     hasContain = false;
  46.                     break;
  47.                 }
  48.  
  49.             }
  50.  
  51.             var topic = item.Key;
  52.             var tags = item.Value;
  53.             if (hasContain)
  54.             {
  55.                 Console.WriteLine($"{topic} | #{string.Join(", #", tags)}");
  56.             }
  57.         }
  58.        
  59.        
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement