Advertisement
Guest User

Untitled

a guest
Apr 2nd, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace citiesByContinentAndCountry
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. // Dictionary<string, Dictionary<string, List<string>>> database = new Dictionary<string, Dictionary<string, List<string>>>();
  12.  
  13. Dictionary<string, Countries> database = new Dictionary<string, Countries>();
  14.  
  15. int numberOfInputs = int.Parse(Console.ReadLine());
  16.  
  17. for (int i = 0; i < numberOfInputs; i++)
  18. {
  19. string[] currentInput = Console.ReadLine()
  20. .Split(" ");
  21.  
  22. string continent = currentInput[0];
  23. string county = currentInput[1];
  24. string city = currentInput[2];
  25.  
  26. Countries currentCountry = new Countries(county, city);
  27.  
  28. if (!database.ContainsKey(continent))
  29. {
  30. database.Add(continent, currentCountry);
  31. }
  32.  
  33. else if (database.ContainsKey(continent))
  34. {
  35. if (!database[continent].Country.Contains(county))
  36. {
  37. database[continent]
  38. }
  39.  
  40. if (database[continent].Country.Contains(county))
  41. {
  42. if (!database[continent].Country.Contains(city))
  43. {
  44. database[continent].Country.Insert(0, city);
  45. }
  46. else
  47. {
  48. database[continent].Cities.Add(city);
  49. }
  50. }
  51. }
  52. }
  53. }
  54. }
  55.  
  56. class Countries
  57. {
  58. public Countries(string country, string city)
  59. {
  60. this.Country = country;
  61. this.Cities = new List<string>();
  62. Cities.Add(city);
  63. }
  64. public string Country { get; set; }
  65. public List<string> Cities { get; set; }
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement