Advertisement
Guest User

Untitled

a guest
Oct 10th, 2015
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8.  
  9. class PopulationCounter
  10. {
  11. static void Main()
  12. {
  13. var dataPopulation = new Dictionary<string, Dictionary<string, int>>();
  14. string dataInput = Console.ReadLine();
  15. while (dataInput != "report")
  16. {
  17. string[] dataArray = dataInput.Trim().Split('|');
  18. string country = dataArray[1];
  19. string city = dataArray[0];
  20. int population = int.Parse(dataArray[2]);
  21. if (!(dataPopulation.ContainsKey(country)))
  22. {
  23. dataPopulation.Add(country, new Dictionary<string, int>());
  24. dataPopulation[country].Add(city, population);
  25. }
  26. else if (!(dataPopulation[country].ContainsKey(city)))
  27. {
  28. dataPopulation[country].Add(city, population);
  29. }
  30.  
  31. dataInput = Console.ReadLine();
  32. }
  33.  
  34. foreach (var item in dataPopulation)
  35. {
  36. var sumPopulationCountry = item.Value.Sum(x => x.Value);
  37. Console.WriteLine("{0} (total population: {1})", item.Key, sumPopulationCountry);
  38. foreach (var itemOne in item.Value)
  39. {
  40. Console.WriteLine("=>{0}: {1}", itemOne.Key, itemOne.Value);
  41. }
  42. }
  43.  
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement