Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _01_Dictionary
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, List<string>> words = new Dictionary<string, List<string>>();
- for (int i = 1; i <= 3; i++)
- {
- string command = Console.ReadLine();
- if (i == 1)
- {
- string[] commandArr = command.Split(" | ");
- for (int j = 0; j < commandArr.Length; j++)
- {
- string[] resultArr = commandArr[j].Split(": ");
- if (!(words.ContainsKey(resultArr[0])))
- {
- words.Add(resultArr[0], new List<string>());
- }
- words[resultArr[0]].Add(resultArr[1]);
- }
- }
- else if (i == 2)
- {
- string[] checkArr = command.Split(" | ");
- int count = 0;
- foreach (var name in words.Keys.OrderBy(k => k))
- {
- string result = checkArr[count];
- count++;
- if (words.ContainsKey(result))
- {
- Console.WriteLine($"{name}");
- foreach (var item in words[name].OrderByDescending(x => x.Length))
- {
- Console.WriteLine($" -{item}");
- }
- }
- }
- }
- else
- {
- if (command == "List")
- {
- foreach (var item in words.OrderBy(x => x.Key))
- {
- Console.Write(item.Key + " ");
- }
- Console.WriteLine();
- }
- else if (command == "End")
- {
- return;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement