Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace _04TravelMap
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, Dictionary<string, int>> countryTownCost = new Dictionary<string, Dictionary<string, int>>();
- while (true)
- {
- string command = Console.ReadLine();
- if(command == "END")
- {
- break;
- }
- string[] tokens = command.Split(" > ");
- string country = tokens[0];
- string town = tokens[1];
- int price = int.Parse(tokens[2]);
- if(!countryTownCost.ContainsKey(country))
- {
- countryTownCost.Add(country, new Dictionary<string, int>());
- countryTownCost[country].Add(town, price);
- }
- else if (countryTownCost.ContainsKey(country)==true && countryTownCost[country].ContainsKey(town)==false)
- {
- countryTownCost[country].Add(town, price);
- }
- else if (countryTownCost.ContainsKey(country) == true && countryTownCost[country].ContainsKey(town) == true)
- {
- if(price< countryTownCost[country][town])
- {
- countryTownCost[country][town] = price;
- }
- }
- }
- foreach (var kvp in countryTownCost.OrderBy(x=>x.Key))
- {
- string countryName = kvp.Key;
- Console.Write(countryName + " -> ");
- foreach (var inner in kvp.Value.OrderBy(x=>x.Value))
- {
- Console.Write($"{inner.Key} -> {inner.Value} ");
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement