Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace zad4
- {
- class Program
- {
- static void Main(string[] args)
- {
- var countrys = new Dictionary<string, List<string>>();
- here:
- var command = Console.ReadLine();
- while(command != "End")
- {
- var commandArgs = command.Split();
- if(commandArgs[0] == "Add")
- {
- var country = commandArgs[1];
- List<string> cities = commandArgs.Skip(2).ToList();
- if (!countrys.ContainsKey(country))
- {
- countrys.Add(commandArgs[1], new List<string>());
- }
- countrys[country].AddRange(cities);
- }
- else if (commandArgs[0] == "Remove")
- {
- bool test = false;
- string cities = commandArgs[1];
- foreach (var country in countrys.Values)
- {
- if (country.Contains(cities))
- {
- country.Remove(cities);
- test = true;
- break;
- }
- else
- {
- test = false;
- }
- }
- if (!test) Console.WriteLine($"City {commandArgs[1]} not found");
- }
- goto here;
- }
- foreach (var country in countrys.OrderByDescending(x => x.Value.Count).ThenBy(x => x.Key))
- {
- string cities = string.Join(", ", country.Value);
- var numberOfCities = country.Value.Count;
- Console.WriteLine($"{country.Key} has {numberOfCities} cities and they are: {cities}");
- }
- }
- }
- }
- /*
- Add Germany Berlin
- Add USA Miami
- Add USA NewYork
- Add UK London
- Add UK Bristol
- Remove Kaspichan
- End
- Add Germany Berlin
- Add Germany Hannover
- Add Bulgaria Sofia
- Add Bulgaria Plovdiv
- Remove Berlin
- Add Bulgaria Varna
- Add Bolivia Sucre
- End
- Remove aa
- Remove bb
- Add cc c1
- End
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement