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.Text;
- using System.Threading.Tasks;
- namespace _04.Group_Continents__Countries_and_Cities
- {
- class Program
- {
- static void Main(string[] args)
- {
- var continentData = new SortedDictionary<string, SortedDictionary<string, SortedSet<string>>>();
- var n = int.Parse(Console.ReadLine());
- 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 (!continentData.ContainsKey(continent))
- {
- continentData.Add(continent, new SortedDictionary<string, SortedSet<string>>());
- continentData[continent] = new SortedDictionary<string, SortedSet<string>>
- {
- {country, new SortedSet<string>()}
- };
- }
- else
- {
- if (!continentData[continent].ContainsKey(country))
- {
- continentData[continent].Add(country, new SortedSet<string>());
- }
- }
- continentData[continent][country].Add(city);
- }
- foreach (var continentContries in continentData)
- {
- var continentName = continentContries.Key;
- var countries = continentContries.Value;
- Console.WriteLine($"{continentName}:");
- foreach (var countryCities in countries)
- {
- var countryName = countryCities.Key;
- var cities = countryCities.Value;
- Console.WriteLine($" {countryName} -> {string.Join(", ", cities)}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement