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 Cities_by_Continent_and_Country
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, Dictionary<string, List<string>>> continents = new Dictionary<string, Dictionary<string, List<string>>>();
- int cnt = int.Parse(Console.ReadLine());
- for (int i = 0; i < cnt; i++)
- {
- string[] input = Console.ReadLine().Split(' ').ToArray();
- string continent = input[0];
- string country = input[1];
- string city = input[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 (KeyValuePair<string, Dictionary<string, List<string>>> continent in continents)
- {
- string name = continent.Key;
- Dictionary<string, List<string>> countries = continent.Value;
- Console.WriteLine($"{name}:");
- foreach(KeyValuePair <string, List<string>> country in countries)
- {
- string nameCountry = country.Key;
- List<string> cities = country.Value;
- Console.WriteLine("{0} -> {1}", nameCountry, string.Join(", ", cities));
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement