ventsislav83

Friends from Rainy Universe

May 28th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace friendsFromRainyUniverse
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var input = Console.ReadLine().Split(new char[] { '-', '>', ':' }, StringSplitOptions.RemoveEmptyEntries);
  14.             var result = new SortedDictionary<string, Dictionary<string, int>>();
  15.             string personName = input[0];
  16.             string liquidName = input[1];
  17.             int jarCount = int.Parse(input[2]);
  18.  
  19.             while (input[0] != "End")
  20.             {
  21.                 personName = input[0];
  22.                 liquidName = input[1];
  23.                 jarCount = int.Parse(input[2]);
  24.  
  25.                 var currenDic = new Dictionary<string, int>();
  26.  
  27.                 if (!currenDic.ContainsKey(liquidName))
  28.                 {
  29.                     currenDic.Add(liquidName, jarCount);
  30.  
  31.                 }
  32.                
  33.                 if (!result.ContainsKey(personName))
  34.                 {
  35.                     result.Add(personName, currenDic);
  36.  
  37.  
  38.                 }
  39.                 else if (!result[personName].ContainsKey(liquidName))
  40.                 {
  41.  
  42.                     result[personName].Add(liquidName, jarCount);
  43.  
  44.                 }
  45.  
  46.  
  47.  
  48.                 input = Console.ReadLine().Split(new char[] { ' ', '-', '>', ':' }, StringSplitOptions.RemoveEmptyEntries);
  49.             }
  50.  
  51.  
  52.             foreach (var person in result)
  53.             {
  54.                 Console.WriteLine($"{person.Key} Liquids:");
  55.  
  56.                 foreach (var liquid in person.Value)
  57.                 {
  58.  
  59.                     Console.WriteLine($"--- {liquid.Key}: { liquid.Value}");
  60.                 }
  61.  
  62.             }
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment