Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace citiesByContinentAndCountry
- {
- class Program
- {
- static void Main(string[] args)
- {
- // Dictionary<string, Dictionary<string, List<string>>> database = new Dictionary<string, Dictionary<string, List<string>>>();
- Dictionary<string, Countries> database = new Dictionary<string, Countries>();
- int numberOfInputs = int.Parse(Console.ReadLine());
- for (int i = 0; i < numberOfInputs; i++)
- {
- string[] currentInput = Console.ReadLine()
- .Split(" ");
- string continent = currentInput[0];
- string county = currentInput[1];
- string city = currentInput[2];
- Countries currentCountry = new Countries(county, city);
- if (!database.ContainsKey(continent))
- {
- database.Add(continent, currentCountry);
- }
- else if (database.ContainsKey(continent))
- {
- if (!database[continent].Country.Contains(county))
- {
- database[continent]
- }
- if (database[continent].Country.Contains(county))
- {
- if (!database[continent].Country.Contains(city))
- {
- database[continent].Country.Insert(0, city);
- }
- else
- {
- database[continent].Cities.Add(city);
- }
- }
- }
- }
- }
- }
- class Countries
- {
- public Countries(string country, string city)
- {
- this.Country = country;
- this.Cities = new List<string>();
- Cities.Add(city);
- }
- public string Country { get; set; }
- public List<string> Cities { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement