Advertisement
WindFell

Untitled

May 28th, 2018
392
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 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.             string input;
  14.             var result = new SortedDictionary<string, Dictionary<string, int>>();
  15.  
  16.             while ((input = Console.ReadLine()) != "End")
  17.             {
  18.                 string[] inputArgs = input.Split(new char[] { ' ', '-', '>', ':' }, StringSplitOptions.RemoveEmptyEntries);
  19.                 string personName = inputArgs[0];
  20.                 string liquidName = inputArgs[1];
  21.                 int jarCount = int.Parse(inputArgs[2]);
  22.  
  23.                 if (!result.ContainsKey(personName))
  24.                 {
  25.                     result.Add(personName, new Dictionary<string, int>());
  26.                 }
  27.  
  28.                 if (!result[personName].ContainsKey(liquidName))
  29.                 {
  30.  
  31.                     result[personName].Add(liquidName, 0);
  32.                 }
  33.  
  34.                 result[personName][liquidName] += jarCount;
  35.             }
  36.  
  37.  
  38.             foreach (var person in result)
  39.             {
  40.                 Console.WriteLine($"{person.Key} Liquids:");
  41.  
  42.                 foreach (var liquid in person.Value.OrderBy(l => l.Value))
  43.                 {
  44.  
  45.                     Console.WriteLine($"--- {liquid.Key}: { liquid.Value}");
  46.                 }
  47.  
  48.             }
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement