Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace _1._Dictionary
- {
- class Program
- {
- static void Main(string[] args)
- {
- //First command start
- var firstCommand = Console.ReadLine()
- .Split(" | ")
- .ToList();
- var result = new List<string>();
- for (int i = 0; i < firstCommand.Count; i++)
- {
- string[] check = firstCommand[i].Split(": ");
- result.Add(check[0]);
- result.Add(check[1]);
- }
- var dict = new SortedDictionary<string, List<string>>();
- for (int i = 0; i < result.Count; i += 2)
- {
- if (dict.ContainsKey(result[i]))
- {
- dict[result[i]].Add(result[i + 1]);
- }
- else
- {
- dict.Add(result[i], new List<string> { result[i + 1] });
- }
- }
- //firstCommand end
- //secondCommand start
- var secondCommand = Console.ReadLine()
- .Split(" | ")
- .ToList();
- for (int i = 0; i < secondCommand.Count; i++)
- {
- if (dict.ContainsKey(secondCommand[i]))
- {
- Console.WriteLine(secondCommand[i]);
- foreach (var value in dict[secondCommand[i]])
- {
- Console.WriteLine($" -{value}");
- }
- }
- }
- //secondCommand end
- while (true)
- {
- var thirdCommand = Console.ReadLine().ToLower();
- if (thirdCommand == "end")
- {
- break;
- }
- else if (thirdCommand == "list")
- {
- foreach (var item in dict)
- {
- Console.Write(item.Key + " ");
- }
- Console.WriteLine();
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement