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.Threading.Tasks;
- namespace _05NestedDictionariesExcercisesDic_RefAdvanced
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, List<int>> data = new Dictionary<string, List<int>>();
- string input = Console.ReadLine();
- while(input!="end")
- {
- string []inputTokens = input.Split(new string[] { "->" }
- , StringSplitOptions.RemoveEmptyEntries).ToArray();
- string name = inputTokens[0];
- if(IsName(inputTokens[1]))
- {
- string otherName = inputTokens[1];
- if(data.ContainsKey(otherName))
- {
- List<int> otherNumbers = data[otherName];
- if(!data.ContainsKey(name))
- {
- data.Add(name, new List<int>());
- }
- data[name].Clear();
- data[name].AddRange(otherNumbers);
- }
- }
- else
- {
- int[] numbers = inputTokens[1].Split(new string[] { ", " }
- , StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse).ToArray();
- if (!data.ContainsKey(name))
- {
- data.Add(name, new List<int>());
- }
- data[name].AddRange(numbers);
- }
- input = Console.ReadLine();
- }
- foreach (KeyValuePair<string,List<int>> item in data)
- {
- string name = item.Key;
- List<int> num = item.Value;
- Console.WriteLine($"{name}=== {string.Join(", ",num)}");
- }
- }
- static bool IsName(string input)
- {
- foreach (char ch in input)
- {
- if (char.IsLetter(ch))
- {
- return true;
- }
- }
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment