Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 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 _5._Lambada_Expressions
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. var data = new Dictionary<string, string>();
  14.  
  15. string input = Console.ReadLine();
  16. int dance = 1;
  17. while (input != "lambada")
  18. {
  19. string[] tokens = input.Split(new string[] { " => " }, StringSplitOptions.RemoveEmptyEntries);
  20. if (tokens[0] == "dance")
  21. {
  22. dance++;
  23. foreach (var item in data.ToDictionary(e => e.Key, e => e.Value))
  24. {
  25. List<string> currentDance = item.Value.Split('.').ToList();
  26. string selectorObject = currentDance[0];
  27. string property = currentDance.Last();
  28. string newSelector = string.Empty;
  29.  
  30. for (int i = 0; i < dance; i++)
  31. {
  32. newSelector += selectorObject + ".";
  33. }
  34. data[item.Key] = newSelector + property;
  35. }
  36.  
  37. }
  38. else
  39. {
  40. string key = tokens[0];
  41. string value = tokens[1];
  42. if (!data.ContainsKey(key))
  43. {
  44. data.Add(key, string.Empty);
  45. }
  46. data[key] = value;
  47. }
  48.  
  49. input = Console.ReadLine();
  50. }
  51. foreach (var item in data)
  52. {
  53. Console.WriteLine($"{item.Key} => {item.Value}");
  54. }
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement