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.Threading.Tasks;
- namespace dictRef
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, List<string>> people = new Dictionary<string, List<string>>();
- string input = Console.ReadLine();
- while (!(input == "end"))
- {
- string[] inputTokkens = input.Split(new string[] { " -> ", ", " }, StringSplitOptions.RemoveEmptyEntries);
- string name = inputTokkens[0];
- if (!(people.ContainsKey(name)))
- {
- people.Add(name, new List<string>());
- for (int i = 1; i < inputTokkens.Length; i++)
- {
- int number = 0;
- if (int.TryParse(inputTokkens[i], out number))
- {
- people[name].Add(inputTokkens[i]);
- }
- else
- {
- if (people.ContainsKey(inputTokkens[i]))
- {
- people[name] = people[inputTokkens[i]];
- }
- else
- {
- people.Remove(name);
- }
- }
- }
- }
- else
- {
- for (int i = 1; i < inputTokkens.Length; i++)
- {
- int number = 0;
- if (int.TryParse(inputTokkens[i], out number))
- {
- people[name].Add(inputTokkens[i]);
- }
- else
- {
- if (people.ContainsKey(inputTokkens[i]))
- {
- people[name] = people[inputTokkens[i]];
- }
- else
- {
- people.Remove(name);
- }
- }
- }
- }
- input = Console.ReadLine();
- }
- foreach (KeyValuePair<string, List<string>> person in people)
- {
- string name = person.Key;
- List<string> numbers = person.Value;
- Console.WriteLine($"{name} === {string.Join(", ", numbers)}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement