WindFell

Untitled

May 28th, 2018
538
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 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.                 if (!result.ContainsKey(personName))
  26.                 {
  27.                     result.Add(personName, new Dictionary<string, int>());
  28.                 }
  29.  
  30.                 if (!result[personName].ContainsKey(liquidName))
  31.                 {
  32.  
  33.                     result[personName].Add(liquidName, 0);
  34.                 }
  35.  
  36.                 result[personName][liquidName] += jarCount;
  37.  
  38.  
  39.  
  40.                 input = Console.ReadLine().Split(new char[] { ' ', '-', '>', ':' }, StringSplitOptions.RemoveEmptyEntries);
  41.             }
  42.  
  43.  
  44.             foreach (var person in result)
  45.             {
  46.                 Console.WriteLine($"{person.Key} Liquids:");
  47.  
  48.                 foreach (var liquid in person.Value.OrderBy(l => l.Value))
  49.                 {
  50.  
  51.                     Console.WriteLine($"--- {liquid.Key}: { liquid.Value}");
  52.                 }
  53.  
  54.             }
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment