Advertisement
Guest User

muti

a guest
Oct 17th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.55 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Security.Cryptography.X509Certificates;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace _07.PopulationCounter
  9. {
  10.     class PopulationCounter
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string input = Console.ReadLine();
  15.             var outPut = new Dictionary<string, Dictionary<string, decimal>>();
  16.             while (input != "report")
  17.             {
  18.                 var cities = input.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  19.  
  20.                 string country = cities[1];
  21.                 string city = cities[0];
  22.                 int population = int.Parse(cities[2]);
  23.                 if (outPut.ContainsKey(cities[1]))
  24.                 {
  25.                     outPut[country].Add(city, population);
  26.  
  27.                 }
  28.                 else
  29.                 {
  30.                     outPut.Add(country, new Dictionary<string, decimal>());
  31.                     outPut[country].Add(city, population);
  32.                 }
  33.                 input = Console.ReadLine();
  34.             }
  35.  
  36.             foreach (var oPair in outPut.OrderByDescending(d => d.Value.Values.Sum()))
  37.             {
  38.                 Console.WriteLine("{0} (total population: {1})", oPair.Key, oPair.Value.Values.Sum());
  39.                 foreach (var item in oPair.Value.OrderByDescending(x => x.Value))
  40.                 {
  41.                     Console.WriteLine("=>{0}: {1}", item.Key, item.Value);
  42.                 }
  43.             }
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement