Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Security.Cryptography.X509Certificates;
- using System.Text;
- using System.Threading.Tasks;
- namespace _07.PopulationCounter
- {
- class PopulationCounter
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- var outPut = new Dictionary<string, Dictionary<string, decimal>>();
- while (input != "report")
- {
- var cities = input.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries).ToList();
- string country = cities[1];
- string city = cities[0];
- int population = int.Parse(cities[2]);
- if (outPut.ContainsKey(cities[1]))
- {
- outPut[country].Add(city, population);
- }
- else
- {
- outPut.Add(country, new Dictionary<string, decimal>());
- outPut[country].Add(city, population);
- }
- input = Console.ReadLine();
- }
- foreach (var oPair in outPut.OrderByDescending(d => d.Value.Values.Sum()))
- {
- Console.WriteLine("{0} (total population: {1})", oPair.Key, oPair.Value.Values.Sum());
- foreach (var item in oPair.Value.OrderByDescending(x => x.Value))
- {
- Console.WriteLine("=>{0}: {1}", item.Key, item.Value);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement