AleksandarKostadinov

07. Population Counter

Feb 4th, 2017
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1. namespace _07.PopulationCounter
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.  
  7.     public class PeopleInCountries
  8.     {
  9.         public static void Main()
  10.         {
  11.             var tokens = Console.ReadLine().Split('|');
  12.             var countries = new Dictionary<string, Dictionary<string, long>>();
  13.  
  14.             while (tokens[0] != "report")
  15.             {
  16.                 var countryName = tokens[1];
  17.  
  18.                 if (!countries.ContainsKey(countryName))
  19.                 {
  20.                     countries[countryName] = new Dictionary<string, long>();
  21.                 }
  22.  
  23.                 var cityName = tokens[0];
  24.                 var population = long.Parse(tokens[2]);
  25.  
  26.                 countries[countryName][cityName] = population;
  27.  
  28.                 tokens = Console.ReadLine().Split('|');
  29.             }
  30.  
  31.             countries.OrderByDescending(x => x.Value.Select(y => y.Value).Sum()).ToDictionary(p => p.Key, p.key);
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment