Advertisement
YavorGrancharov

Forum_Topics(copy)

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