Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class Program
- {
- static void Main()
- {
- var population = new Dictionary<string, Dictionary<string, long>>();
- string input = Console.ReadLine();
- while (input != "report")
- {
- string[] tokens = input.Split(new[] {'|'}).ToArray();
- string city = tokens[0];
- string country = tokens[1];
- long populations = long.Parse(tokens[2]);
- if (!population.ContainsKey(country))
- {
- population.Add(country, new Dictionary<string, long>());
- population[country].Add(city, populations);
- }
- else
- {
- if (!population[country].ContainsKey(city))
- {
- population[country].Add(city, populations);
- }
- }
- input = Console.ReadLine();
- }
- foreach (var countries in population
- .OrderByDescending(x=>x.Value.Values.Sum()))
- {
- Console.WriteLine($"{countries.Key}: ");
- foreach (var cities in countries.Value.OrderByDescending(x=>x.Value))
- {
- Console.WriteLine($"=>{cities.Key}: {cities.Value} ");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment