Advertisement
Aborigenius

LambadaExpresions

Aug 17th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.79 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 LambadaExpresions
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string input = Console.ReadLine();
  14.             Dictionary<string, Dictionary<string, string>> data =
  15.                 new Dictionary<string, Dictionary<string, string>>();
  16.             while (input != "lambada")
  17.             {
  18.                 string[] inputTokens = input.Split(new string[]
  19.                 { " => ", "." }, StringSplitOptions.RemoveEmptyEntries);
  20.  
  21.                 if (inputTokens[0] == "dance")
  22.                 {
  23.                                 {
  24.                                       data = data.ToDictionary(selectorData => selectorData.Key,
  25.                                        selectorData => selectorData.Value
  26.                                        .ToDictionary(selectorObjectData => selectorObjectData.Key,
  27.                                        selectorObjectData => selectorObjectData.Key + "."
  28.                                        + selectorObjectData.Value));
  29.                                   }
  30.                     /*  
  31.                       var selectors = data.Keys.ToList();
  32.  
  33.                       foreach (var selector in selectors)
  34.                       {
  35.                           var selectorObjects = data[selector].Keys.ToList();
  36.                           foreach (var selectorObject in selectorObjects)
  37.                           {
  38.                               data[selector][selectorObject] =
  39.                                   selectorObject + "." + data[selector][selectorObject];
  40.                           }
  41.                       }
  42.                       */
  43.                 }
  44.  
  45.                 else
  46.                 {
  47.                     string selector = inputTokens[0];
  48.                     string selectorObject = inputTokens[1];
  49.                     string selectorProperty = inputTokens[2];
  50.  
  51.                     if (!data.ContainsKey(selector))
  52.                     {
  53.                         data.Add(selector, new Dictionary<string, string>());
  54.                     }
  55.                     data[selector][selectorObject] = selectorProperty;
  56.                 }
  57.                 input = Console.ReadLine();
  58.             }
  59.  
  60.             foreach (var item in data)
  61.             {
  62.                 string selector = item.Key;
  63.                 Dictionary<string, string> selectorObjectData = item.Value;
  64.  
  65.                 foreach (var sel in selectorObjectData)
  66.                 {
  67.                     string selectorObject = sel.Key;
  68.                     string property = sel.Value;
  69.  
  70.                     Console.WriteLine($"{selector} => {selectorObject}.{property}");
  71.                 }
  72.             }
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement