Advertisement
Guest User

04. International SoftUniada

a guest
Apr 10th, 2019
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _04._International_SoftUniada
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string input = Console.ReadLine();
  12. Dictionary<string, Dictionary<string, int>> result = new Dictionary<string, Dictionary<string, int>>();
  13. while (input !="END")
  14. {
  15. string[] line = input.Split(" -> ");
  16. string counrty = line[0];
  17. string name = line[1];
  18. int point = int.Parse(line[2]);
  19. if (!result.ContainsKey(counrty))
  20. {
  21. result.Add(counrty, new Dictionary<string, int>());
  22. result[counrty].Add(name, point);
  23. }
  24. else if (result.ContainsKey(counrty))
  25. {
  26. if (!result[counrty].ContainsKey(name))
  27. {
  28. result[counrty].Add(name, point);
  29. }
  30. else if (result[counrty].ContainsKey(name))
  31. {
  32. result[counrty][name] += point;
  33. }
  34. }
  35.  
  36. input = Console.ReadLine();
  37. }
  38.  
  39. foreach (var item in result.OrderByDescending(x=>x.Value.Values.Sum()))
  40. {
  41. Console.WriteLine($"{item.Key}: {item.Value.Values.Sum()}");
  42. foreach (var kvp in item.Value)
  43. {
  44. Console.WriteLine($" -- {kvp.Key} -> {kvp.Value}");
  45. }
  46.  
  47. }
  48. }
  49. }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement