Advertisement
NadyaMisheva

durjavi gradove

Mar 17th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. public class Program
  5. {
  6. public static void Main()
  7. {
  8. Dictionary<string, List<string>> tourist = new Dictionary<string, List<string>> ();
  9. while(true)
  10. {
  11. string[] command = Console.ReadLine().Split(' ');
  12. if(command[0] == "End")
  13. {
  14. break;
  15. }
  16. else if(command[0] == "Add")
  17. {
  18. string country = command[1];
  19. string city = command[2];
  20. if(tourist.ContainsKey(country))
  21. {
  22. tourist[country].Add(city);
  23. }
  24. else
  25. {
  26. tourist[country] = new List<string>();
  27. tourist[country].Add(city);
  28. }
  29. /*if(!tourist.ContainsKey(country))
  30. {
  31. tourist[country] = new List<string>();
  32. }
  33. else
  34. {
  35. tourist[country].Add(city);
  36. }*/
  37. }
  38. if(command[0] == "Remove")
  39. {
  40. string city = command[1];
  41. int a = 1;
  42. foreach(string country in tourist.Keys)
  43. {
  44. if(tourist[country].Contains(city))
  45. {
  46. a = 2;
  47. tourist[country].Remove(city);
  48. break;
  49. }
  50. }
  51. if(a == 1)
  52. {
  53. Console.WriteLine("City {0} not found", city);
  54. }
  55.  
  56. }
  57. }
  58. foreach(string country in tourist.Keys)
  59. {
  60. Console.Write("{0} has {1} cities and they are :", country, tourist[country].Count);
  61. Console.WriteLine(string.Join(", ", tourist[country]));
  62. /*foreach(string city in tourist[country])
  63. {
  64. Console.Write(city + ", ");
  65. }
  66. Console.WriteLine( );*/
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement