Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- class PopulationCounter
- {
- static void Main()
- {
- var dataPopulation = new Dictionary<string, Dictionary<string, int>>();
- string dataInput = Console.ReadLine();
- while (dataInput != "report")
- {
- string[] dataArray = dataInput.Trim().Split('|');
- string country = dataArray[1];
- string city = dataArray[0];
- int population = int.Parse(dataArray[2]);
- if (!(dataPopulation.ContainsKey(country)))
- {
- dataPopulation.Add(country, new Dictionary<string, int>());
- dataPopulation[country].Add(city, population);
- }
- else if (!(dataPopulation[country].ContainsKey(city)))
- {
- dataPopulation[country].Add(city, population);
- }
- dataInput = Console.ReadLine();
- }
- foreach (var item in dataPopulation)
- {
- var sumPopulationCountry = item.Value.Sum(x => x.Value);
- Console.WriteLine("{0} (total population: {1})", item.Key, sumPopulationCountry);
- foreach (var itemOne in item.Value)
- {
- Console.WriteLine("=>{0}: {1}", itemOne.Key, itemOne.Value);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement