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