Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- public class Program
- {
- public static void Main()
- {
- Dictionary<string, List<string>> tourist = new Dictionary<string, List<string>> ();
- while(true)
- {
- string[] command = Console.ReadLine().Split(' ');
- if(command[0] == "End")
- {
- break;
- }
- else if(command[0] == "Add")
- {
- string country = command[1];
- string city = command[2];
- if(tourist.ContainsKey(country))
- {
- tourist[country].Add(city);
- }
- else
- {
- tourist[country] = new List<string>();
- tourist[country].Add(city);
- }
- /*if(!tourist.ContainsKey(country))
- {
- tourist[country] = new List<string>();
- }
- else
- {
- tourist[country].Add(city);
- }*/
- }
- if(command[0] == "Remove")
- {
- string city = command[1];
- int a = 1;
- foreach(string country in tourist.Keys)
- {
- if(tourist[country].Contains(city))
- {
- a = 2;
- tourist[country].Remove(city);
- break;
- }
- }
- if(a == 1)
- {
- Console.WriteLine("City {0} not found", city);
- }
- }
- }
- foreach(string country in tourist.Keys)
- {
- Console.Write("{0} has {1} cities and they are :", country, tourist[country].Count);
- Console.WriteLine(string.Join(", ", tourist[country]));
- /*foreach(string city in tourist[country])
- {
- Console.Write(city + ", ");
- }
- Console.WriteLine( );*/
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement