BubaLazi

MultiDIct02Countries Test

Aug 3rd, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.56 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace MultiDictionaries
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var continentsData= new Dictionary<string,Dictionary<string,List<string>>();
  14.             int inputCount = int.Parse(Console.ReadLine());
  15.  
  16.             for(int i = 0; i < inputCount; i++)
  17.             {
  18.                 string[] input = Console.ReadLine().Split(' ');
  19.                 string continentName = input[0];
  20.                 string countryName = input[1];
  21.                 List<string> cityName = input[2];
  22.  
  23.                 if(!continentsData.ContainsKey(continentName))
  24.                 {
  25.                     continentsData.Add(continentName, new Dictionary<string, string>());
  26.                 }
  27.                 continentsData[continentName].Add(countryName, cityName);
  28.             }
  29.            
  30.             foreach(var record in continentsData)
  31.             {
  32.                 string continentName = record.Key;
  33.                 Dictionary<string, string> countriesData = record.Value;
  34.  
  35.                 Console.WriteLine("{0}:", continentName);
  36.                 foreach(KeyValuePair<string, string> countryData in countriesData)
  37.                 {
  38.                     string countryName = countryData.Key;
  39.                     string cityNames = countryData.Value;
  40.                     Console.WriteLine("  {0} --> {1}", countryName, cityNames);
  41.                 }
  42.                
  43.             }
  44.  
  45.  
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment