Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace _03.CitiesByContinentAndCountries
- {
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- public class Program
- {
- public static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- var myDict = new Dictionary<string, Dictionary<string, List<string>>>();
- for (int i = 0; i < n; i++)
- {
- string[] input = Console.ReadLine().Split(' ').ToArray();
- string continent = input[0];
- string country = input[1];
- string town = input[2];
- if (!myDict.ContainsKey(continent))
- {
- myDict.Add(continent, new Dictionary<string, List<string>>());
- }
- if (!myDict[continent].ContainsKey(country))
- {
- myDict[continent].Add(country, new List<string>());
- myDict[continent][country].Add(town);
- }
- }
- string result = string.Join(Environment.NewLine,
- myDict.Select(kvp => $"{kvp.Key}, {kvp.Value.Select(v => $"{v.Key} -> {string.Join(", ", v.Value)}")}"));
- Console.WriteLine(result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement