Advertisement
osman1997

Snowwhite

Jan 6th, 2021
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using System.Collections;
  6.  
  7. class Program
  8. {
  9.  
  10. static void Main()
  11. {
  12.  
  13. string command = Console.ReadLine();
  14.  
  15. Dictionary<string, Dictionary<string, int>> users = new Dictionary<string, Dictionary<string, int>>();
  16.  
  17.  
  18. while(command != "Once upon a time")
  19. {
  20. string[] line = command.Split(" <:> ");
  21. string name = line[0];
  22. string color = line[1];
  23. int points = int.Parse(line[2]);
  24.  
  25. if (!users.ContainsKey(name))
  26. {
  27. users.Add(name, new Dictionary<string, int>()
  28. {
  29. {color, points }
  30. });
  31. }
  32. else
  33. {
  34. if(users.ContainsKey(name) && !users[name].ContainsKey(color))
  35. {
  36. users[name].Add(color, points);
  37. }
  38.  
  39. if(users.ContainsKey(name) && users[name].ContainsKey(color))
  40. {
  41. if(users[name][color] < points)
  42. {
  43. users[name][color] = points;
  44. }
  45. }
  46.  
  47. }
  48.  
  49. command = Console.ReadLine();
  50. }
  51.  
  52.  
  53. foreach (var item in users.OrderByDescending(s => s.Value.Values.Sum()).ThenByDescending(s => s.Value.Values.Count()))
  54. {
  55. foreach (var kvp in item.Value)
  56. {
  57. Console.WriteLine($"({kvp.Key}) {item.Key} <-> {kvp.Value}");
  58. }
  59. }
  60.  
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement