Advertisement
Ivakis

Untitled

Jun 22nd, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace uprajnenie2
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. var dic = new SortedDictionary<string, Dictionary<string, int>>(); //country / town / population
  14.  
  15. for (int i = 0; ; i++)
  16. {
  17. var input = Console.ReadLine().Split('|');
  18.  
  19. if (input[0] == "report")
  20. {
  21. break;
  22. }
  23.  
  24. var country = input[1];
  25. var town = input[0];
  26. var population = int.Parse(input[2]);
  27.  
  28. if (!dic.ContainsKey(country))
  29. {
  30. dic.Add(country, new Dictionary<string, int>());
  31. }
  32. if (!dic[country].ContainsKey(town))
  33. {
  34. dic[country].Add(town, 0);
  35. }
  36.  
  37. dic[country][town] += population;
  38.  
  39. }
  40. foreach (KeyValuePair<string, Dictionary<string, int>> item in dic
  41. .OrderByDescending(a => a.Value.Values.Sum())) // country
  42. {
  43. Console.WriteLine($"{item.Key} (total population: {item.Value.Values.Sum()})");
  44.  
  45.  
  46. foreach (KeyValuePair<string, int> count in item.Value.OrderByDescending(a => a.Value)) // town, populaton
  47. {
  48. Console.WriteLine($"=>{count.Key}: {count.Value} ");
  49. }
  50. }
  51.  
  52. }
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement