YavorGrancharov

Lambada_Expressions(copy)

Jul 22nd, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Lambada_Expressions
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Dictionary<string, Dictionary<string, string>> data =
  12.                 new Dictionary<string, Dictionary<string, string>>();
  13.  
  14.             string input = Console.ReadLine();
  15.  
  16.             while (input != "lambada")
  17.             {
  18.                 string[] inputTokens = input
  19.                     .Split(new string[] { " => ", "." }, StringSplitOptions.RemoveEmptyEntries);
  20.  
  21.                 if (inputTokens[0] == "dance")
  22.                 {
  23.                     data = data
  24.                         .ToDictionary(selectorData => selectorData.Key, selectorData => selectorData.Value
  25.                         .ToDictionary(selectorObjectData => selectorObjectData.Key, selectorObjectData => selectorObjectData.Key + "." + selectorObjectData.Value));
  26.                 }
  27.                 else
  28.                 {
  29.                     string selector = inputTokens[0];
  30.                     string selectorObject = inputTokens[1];
  31.                     string selectorProperty = inputTokens[2];
  32.  
  33.                     if (!data.ContainsKey(selector))
  34.                     {
  35.                         data.Add(selector, new Dictionary<string, string>());
  36.                     }
  37.                     data[selector][selectorObject] = selectorProperty;
  38.                 }
  39.  
  40.                 input = Console.ReadLine();
  41.             }
  42.  
  43.             foreach (var selectorData in data)
  44.             {
  45.                 string selector = selectorData.Key;
  46.                 Dictionary<string, string> selectorObjectsData = selectorData.Value;
  47.  
  48.                 foreach (var selectorObjectData in selectorObjectsData)
  49.                 {
  50.                     string selectorObject = selectorObjectData.Key;
  51.                     string property = selectorObjectData.Value;
  52.  
  53.                     Console.WriteLine("{0} => {1}.{2}", selector, selectorObject, property);
  54.                 }
  55.             }
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment