Advertisement
Guest User

Untitled

a guest
May 28th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.07 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.  
  14.             var input = Console.ReadLine().Split(new char[] { '-', '>', ':' }, StringSplitOptions.RemoveEmptyEntries);
  15.             var result = new SortedDictionary<string, Dictionary<string, int>>();
  16.             string personName = input[0];
  17.             string liquidName = input[1];
  18.             int jarCount = int.Parse(input[2]);
  19.  
  20.             while (input[0] != "End")
  21.             {
  22.                 personName = input[0];
  23.                 liquidName = input[1];
  24.                 jarCount = int.Parse(input[2]);
  25.                 var currenDic = new Dictionary<string, int>();
  26.                 if (currenDic.ContainsKey(liquidName))
  27.                 {
  28.                     currenDic[liquidName] += jarCount;
  29.                    
  30.  
  31.                 }
  32.                 else
  33.                 {
  34.                     currenDic.Add(liquidName, jarCount);
  35.  
  36.  
  37.                 }
  38.                 if (!result.ContainsKey(personName))
  39.                 {
  40.                     result.Add(personName, currenDic);
  41.  
  42.  
  43.                     //result[personName].Add(liquidName, jarCount);
  44.                    
  45.  
  46.                 }
  47.                 else if (!result[personName].ContainsKey(liquidName))
  48.                 {
  49.          
  50.                         result[personName].Add(liquidName, jarCount);
  51.                    
  52.                 }
  53.                
  54.  
  55.  
  56.                 input = Console.ReadLine().Split(new char[] { ' ', '-', '>', ':' }, StringSplitOptions.RemoveEmptyEntries);
  57.             }
  58.  
  59.  
  60.             foreach (var person in result)
  61.             {
  62.                 Console.WriteLine($"{person.Key} Liquids:");
  63.  
  64.                 foreach (var liquid in person.Value.OrderBy(x=>x.Key))
  65.                     {
  66.                  
  67.                     Console.WriteLine($"--- {liquid.Key}: { liquid.Value}");
  68.                 }
  69.  
  70.             }
  71.         }
  72.     }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement