Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _03.Cities_by_Continent_and_Country
- {
- class Program
- {
- static void Main(string[] args)
- {
- var n = int.Parse(Console.ReadLine());
- var continents = new Dictionary<string, Dictionary<string, List<string>>>();
- for (int i = 0; i < n; i++)
- {
- var tokens = Console.ReadLine().Split();
- var continent = tokens[0];
- var country = tokens[1];
- var city = tokens[2];
- if (!continents.ContainsKey(continent))
- {
- continents[continent] = new Dictionary<string,List<string>>();
- }
- if (!continents[continent].ContainsKey(country))
- {
- continents[continent][country] = new List<string>();
- }
- continents[continent][country].Add(city);
- }
- foreach (var continentCountry in continents)
- {
- var continentName = continentCountry.Key;
- var countries = continentCountry.Value;
- Console.WriteLine("{0}:", continentName);
- foreach (var countryCity in countries)
- {
- var countryName = countryCity.Key;
- var cities = countryCity.Value;
- Console.WriteLine(" " + countryName + " -> " + string.Join(", ", cities));
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment