Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _3.Snowflake
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. Dictionary<string, Dictionary<string, int>> dict = new Dictionary<string, Dictionary<string, int>>();
  12.  
  13. string command = Console.ReadLine();
  14.  
  15. while(command != "Once upon a time")
  16. {
  17. string[] text = command.Split(new char[] { '<', ':', '>', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  18. string dwarfName = text[0];
  19. string dwarfHatColor = text[1];
  20. int dwarfPhysics = int.Parse(text[2]);
  21.  
  22. if(dict.ContainsKey(dwarfHatColor) == false)
  23. {
  24. Dictionary<string, int> helper = new Dictionary<string, int>();
  25. helper.Add(dwarfName, dwarfPhysics);
  26. dict.Add(dwarfHatColor, helper);
  27. }
  28. else if(dict[dwarfHatColor].ContainsKey(dwarfName) == false)
  29. {
  30. dict[dwarfHatColor].Add(dwarfName, dwarfPhysics);
  31. }
  32. if (dict[dwarfHatColor][dwarfName] < dwarfPhysics)
  33. {
  34. dict[dwarfHatColor][dwarfName] = dwarfPhysics;
  35. }
  36.  
  37. command = Console.ReadLine();
  38. }
  39.  
  40. foreach (var pair in dict.OrderByDescending(x => x.Value.Values.Sum()))
  41. {
  42. foreach (var item in pair.Value)
  43. {
  44. Console.WriteLine("({0}) {1} <-> {2}", pair.Key , item.Key, item.Value);
  45. }
  46. }
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement