Advertisement
Guest User

Untitled

a guest
Mar 10th, 2020
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace Snowwhite
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. Dictionary<string, Dictionary<string, int>> dwarfs = new Dictionary<string, Dictionary<string, int>>();
  12.  
  13. string input = Console.ReadLine();
  14.  
  15. while (input != "Once upon a time")
  16. {
  17. string[] dwarfsInfo = input.Split(" <:> ");
  18. string dwarfName = dwarfsInfo[0];
  19. string dwarfHat = dwarfsInfo[1];
  20. int physics = int.Parse(dwarfsInfo[2]);
  21.  
  22. if (!dwarfs.ContainsKey(dwarfHat))
  23. {
  24. dwarfs[dwarfHat] = new Dictionary<string, int>();
  25. }
  26.  
  27. if (!dwarfs[dwarfHat].ContainsKey(dwarfName))
  28. {
  29. dwarfs[dwarfHat].Add(dwarfName, physics);
  30. }
  31.  
  32. if (dwarfs[dwarfHat][dwarfName] < physics)
  33. {
  34. dwarfs[dwarfHat][dwarfName] = physics;
  35. }
  36.  
  37.  
  38. input = Console.ReadLine();
  39. }
  40.  
  41. foreach (var hat in dwarfs.OrderByDescending(x => x.Value.Values.Max()).ThenByDescending(x => x.Value.Count()))
  42. {
  43. foreach (var dwarf in hat.Value)
  44. {
  45. Console.WriteLine($"({hat.Key}) {dwarf.Key} <-> {dwarf.Value}");
  46. }
  47. }
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement