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 Dict_Ref_Advanced
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, List<int>> dictionary = new Dictionary<string, List<int>>();
- string inputLine = Console.ReadLine();
- while (inputLine != "end")
- {
- string[] inputData = inputLine.Split(new[] { ' ', '-', '>', ',' }, StringSplitOptions.RemoveEmptyEntries);
- string currentKey = inputData[0];
- var firstValue = -1;
- if (int.TryParse(inputData[1], out firstValue))
- {
- if (!dictionary.ContainsKey(currentKey))
- {
- dictionary[currentKey] = new List<int>();
- }
- for (int i = 1; i < inputData.Length; i++)
- {
- dictionary[currentKey].Add(int.Parse(inputData[i]));
- }
- }
- else
- {
- string otherKey = inputData[1];
- if (dictionary.ContainsKey(otherKey))
- {
- dictionary[currentKey] = new List<int>(dictionary[otherKey]);
- }
- }
- inputLine = Console.ReadLine();
- }//end while
- foreach (var entry in dictionary)
- {
- Console.WriteLine("{0} === {1}", entry.Key, string.Join(", ", entry.Value));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement