Advertisement
YavorGrancharov

Dict_Ref_Advanced(copy)

Jul 14th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.49 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Dict_Ref_Advanced
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Dictionary<string, List<int>> stock = new Dictionary<string, List<int>>();
  12.             string end = Console.ReadLine();
  13.             while (end != "end")
  14.             {
  15.                 string[] input = end.Split(new string[] { " -> " }, StringSplitOptions.RemoveEmptyEntries);
  16.                 string name = input[0];
  17.                 string[] num = input[1].Split(", ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  18.                 int value = 0;
  19.                 if (int.TryParse(num[0], out value))
  20.                 {
  21.                     if (!stock.ContainsKey(name))
  22.                     {
  23.                         stock[name] = new List<int>();
  24.                     }
  25.                     for (int i = 0; i < num.Length; i++)
  26.                     {
  27.                         stock[name].Add(int.Parse(num[i]));
  28.                     }
  29.                 }
  30.                 else
  31.                 {
  32.                     if (stock.ContainsKey(num[0]))
  33.                     {
  34.                         stock[name] = new List<int>(stock[num[0]]);
  35.                     }
  36.                 }
  37.                 end = Console.ReadLine();
  38.             }
  39.             foreach (var name in stock)
  40.             {
  41.                 Console.WriteLine($"{name.Key} === {string.Join(", ", name.Value)}");
  42.             }
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement