Advertisement
valkata

lambadaExpressions

Jul 22nd, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.48 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 lambadaExpressions_05
  8. {
  9.     class lambadaExpressions
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Dictionary<string, Dictionary<string, string>> lambadaExpressions = new Dictionary<string, Dictionary<string, string>>();
  14.  
  15.             string input = Console.ReadLine();
  16.             int dance = 0;
  17.             while (input != "lambada")
  18.             {
  19.                 string[] extract = input.Split(new string[] { " => ", " ", "." }, StringSplitOptions.RemoveEmptyEntries);
  20.                 string selector = extract[0];
  21.                 if (selector == "dance")
  22.                 {
  23.                     dance++;
  24.                 }
  25.                 else
  26.                 {
  27.                     string selectorObject = extract[1];
  28.                     string property = extract[2];
  29.                     if (!lambadaExpressions.ContainsKey(selector))
  30.                     {
  31.                         lambadaExpressions.Add(selector, new Dictionary<string, string>());
  32.                     }
  33.                     if (!lambadaExpressions[selector].ContainsKey(selectorObject))
  34.                     {
  35.                        
  36.                         lambadaExpressions[selector].Add(selectorObject, property);
  37.                     }
  38.                     else
  39.                     {                        
  40.                         lambadaExpressions[selector][selectorObject] =  property;
  41.                     }
  42.                 }
  43.                 input = Console.ReadLine();
  44.             }
  45.  
  46.             foreach (KeyValuePair<string, Dictionary<string, string>> lambadaExpression in lambadaExpressions)
  47.             {
  48.                 string selector = lambadaExpression.Key;
  49.                 Dictionary<string, string> selectorProperties = lambadaExpression.Value;
  50.                 Console.Write($"{selector} => ");
  51.                 foreach (var selectorProperty in selectorProperties)
  52.                 {
  53.                     string selectorObject = selectorProperty.Key;
  54.                     for (int i = 0; i < dance ; i++)
  55.                     {
  56.                         selectorObject += "." + selectorProperty.Key;
  57.                     }
  58.                    
  59.                     string property = selectorProperty.Value;
  60.                     Console.WriteLine($"{selectorObject}.{property}");                
  61.                 }
  62.             }
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement