Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace TestGround
- {
- class Test
- {
- static void Main(string[] args)
- {
- //две структури, залепените двойки ще си ги държим в списък към всеки ключ в долната
- var keys = new Dictionary<string, Dictionary<string, string>>();
- var flattened = new Dictionary<string, List<string>>();
- string input = Console.ReadLine();
- while (input != "end")
- {
- string[] inputs = input.Split(' ');
- if (inputs[0] != "flatten") //пълним си речника стандартно
- {
- string key = inputs[0];
- string innerKey = inputs[1];
- string innerValue = inputs[2];
- if (!keys.ContainsKey(key))
- {
- keys.Add(key, new Dictionary<string, string>());
- }
- if (!keys[key].ContainsKey(innerKey))
- {
- keys[key].Add(innerKey, innerValue);
- }
- else
- {
- keys[key][innerKey] = innerValue;
- }
- }
- else
- {
- string key = inputs[1];
- foreach (var kvp in keys[key]) //пускаме си цикъл по всички вътрешни двойки за този ключ
- {
- if (!flattened.ContainsKey(key))
- {
- flattened.Add(key, new List<string>());
- }
- flattened[key].Add(kvp.Key + kvp.Value); //добавяме си ги залепени в списъка към ключа
- }
- keys[key].Clear(); //изчистваме всички преместени двойки, остава празен речник за следващи ако има
- }
- input = Console.ReadLine();
- }
- foreach (var kvp in keys.OrderByDescending(x => x.Key.Length))
- {
- Console.WriteLine(kvp.Key);
- int counter = 1;
- foreach (var inside in kvp.Value.OrderBy(x => x.Key.Length))
- {
- Console.WriteLine("{0}. {1} - {2}", counter, inside.Key, inside.Value);
- counter++;
- }
- if (flattened.ContainsKey(kvp.Key))
- {
- foreach (var str in flattened[kvp.Key])
- {
- Console.WriteLine("{0}. {1}", counter, str);
- counter++;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement