Advertisement
viraco4a

3_Friends_from_rainy_Universe

Jan 22nd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 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. SortedDictionary<string, Dictionary<string, int>> AllData = new SortedDictionary<string, Dictionary<string, int>>();
  14. string input = Console.ReadLine();
  15. while (input != "End")
  16. {
  17. string[] SplittedInput = input.Split(new string[] { " -> ", ": " }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  18. string NewPersonName = SplittedInput[0];
  19. string LiquidNameForTheNewPerson = SplittedInput[1];
  20. int JarCountForNewPerson = int.Parse(SplittedInput[2]);
  21.  
  22. if (!AllData.ContainsKey(NewPersonName))
  23. {
  24. AllData[NewPersonName] = new Dictionary<string, int>();
  25. AllData[NewPersonName][LiquidNameForTheNewPerson] = JarCountForNewPerson;
  26. }
  27. else if (AllData[NewPersonName].ContainsKey(LiquidNameForTheNewPerson))
  28. {
  29. int NewJar = AllData[NewPersonName][LiquidNameForTheNewPerson] + JarCountForNewPerson;
  30. AllData[NewPersonName][LiquidNameForTheNewPerson] = NewJar;
  31. }
  32. else
  33. {
  34. AllData[NewPersonName][LiquidNameForTheNewPerson] = JarCountForNewPerson;
  35. }
  36. input = Console.ReadLine();
  37. }
  38.  
  39. foreach (var Person in AllData)
  40. {
  41. Console.WriteLine($"{Person.Key} Liquids:");
  42. foreach (var item in Person.Value.OrderBy(x => x.Value))
  43. {
  44. Console.WriteLine($"--- {item.Key}: {item.Value}");
  45. }
  46. }
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement