Advertisement
Taniaaleksandrova

04. Snowwhite

Jul 21st, 2020
369
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _04._Snowwhite
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string input = string.Empty;
  12.  
  13. var dwarfs = new Dictionary<string, Dictionary<string, int>>();
  14.  
  15. while ((input = Console.ReadLine()) != "Once upon a time")
  16. {
  17. string name = input.Split(" <:> ")[0];
  18. string color = input.Split(" <:> ")[1];
  19. int physics = int.Parse(input.Split(" <:> ")[2]);
  20.  
  21. if(dwarfs.ContainsKey(color))
  22. {
  23. if(dwarfs[color].ContainsKey(name))
  24. {
  25. if(dwarfs[color][name] < physics)
  26. {
  27. dwarfs[color][name] = physics;
  28. }
  29. }
  30. else
  31. {
  32. dwarfs[color].Add(name, physics);
  33. }
  34. }
  35. else
  36. {
  37. dwarfs.Add(color, new Dictionary<string, int>());
  38. dwarfs[color].Add(name, physics);
  39. }
  40. }
  41.  
  42. foreach (var item in dwarfs)
  43. {
  44. foreach (var items in dwarfs[item.Key])
  45. {
  46. if(items.Value == 0)
  47. {
  48. dwarfs[item.Key].Remove(items.Key);
  49. }
  50. }
  51.  
  52. if(item.Value.Count == 0)
  53. {
  54. dwarfs.Remove(item.Key);
  55. }
  56. }
  57.  
  58. dwarfs = dwarfs.OrderByDescending(x => x.Value.Values.Max()).ThenByDescending(x => x.Value.Values.Count).ToDictionary(a => a.Key, b => b.Value);
  59. ;
  60. foreach (var item in dwarfs)
  61. {
  62. foreach (var items in dwarfs[item.Key].OrderByDescending(x => x.Value))
  63. {
  64. Console.WriteLine($"({item.Key}) {items.Key} <-> {items.Value}");
  65. }
  66. }
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement