Advertisement
simonradev

asd

Dec 28th, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 KB | None | 0 0
  1. namespace _03.CitiesByContinentAndCountries
  2. {
  3.     using System;
  4.     using System.Collections;
  5.     using System.Collections.Generic;
  6.     using System.Linq;
  7.  
  8.     public class Program
  9.     {
  10.         public static void Main()
  11.         {
  12.             int n = int.Parse(Console.ReadLine());
  13.             var myDict = new Dictionary<string, Dictionary<string, List<string>>>();
  14.  
  15.             for (int i = 0; i < n; i++)
  16.             {
  17.  
  18.                 string[] input = Console.ReadLine().Split(' ').ToArray();
  19.                 string continent = input[0];
  20.                 string country = input[1];
  21.                 string town = input[2];
  22.  
  23.                 if (!myDict.ContainsKey(continent))
  24.                 {
  25.                     myDict.Add(continent, new Dictionary<string, List<string>>());
  26.  
  27.                 }
  28.  
  29.                 if (!myDict[continent].ContainsKey(country))
  30.                 {
  31.                     myDict[continent].Add(country, new List<string>());
  32.                     myDict[continent][country].Add(town);
  33.                 }
  34.             }
  35.             string result = string.Join(Environment.NewLine,
  36.                                         myDict.Select(kvp => $"{kvp.Key}, {kvp.Value.Select(v => $"{v.Key} -> {string.Join(", ", v.Value)}")}"));
  37.             Console.WriteLine(result);
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement