Advertisement
YavorGrancharov

Key_Key_Value_Value(copy)(dictlist)

Jul 11th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.55 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Key_Key_Value_Value
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string key = Console.ReadLine();
  12.  
  13.             string value = Console.ReadLine();
  14.  
  15.             Dictionary<string, List<string>> stock = new Dictionary<string, List<string>>();
  16.  
  17.             int n = int.Parse(Console.ReadLine());
  18.             for (int i = 0; i < n; i++)
  19.             {
  20.                 string[] input = Console.ReadLine().Split(new string[] { " => " }, StringSplitOptions.RemoveEmptyEntries);
  21.  
  22.                 string leftEntry = input[0];
  23.  
  24.                 List<string> raightEntry = input[1].Split(';').ToList();
  25.  
  26.                 if (leftEntry.Contains(key))
  27.                 {
  28.                     if (!stock.ContainsKey(leftEntry))
  29.                     {
  30.                         stock[leftEntry] = new List<string>();
  31.                     }
  32.                     foreach (string word in raightEntry)
  33.                     {
  34.                         if (word.Contains(value))
  35.                         {
  36.                             stock[leftEntry].Add(word);
  37.                         }
  38.                     }
  39.                 }
  40.             }
  41.             foreach (KeyValuePair<string, List<string>> match in stock)
  42.             {
  43.                 Console.WriteLine("{0}:", match.Key);
  44.                 foreach (var val in match.Value)
  45.                 {
  46.                     Console.WriteLine("-{0}", val);
  47.                 }
  48.             }
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement