stefan1919

NightLife

Sep 22nd, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication7
  8. {
  9.     class Program
  10.     {
  11.  
  12.         static void Main(string[] args)
  13.         {
  14.             Dictionary<string, SortedDictionary<string, List<string>>> cities = new Dictionary<string, SortedDictionary<string, List<string>>>();
  15.             string input = Console.ReadLine();
  16.             string[] inputData = input.Split(';');
  17.             while (input != "END")
  18.             {
  19.                 if (cities.ContainsKey(inputData[0]) == false)
  20.                 {
  21.                     cities.Add(inputData[0], new SortedDictionary<string, List<string>>());
  22.                     List<string> check = new List<string>();
  23.                     cities[inputData[0]].Add(inputData[1], new List<string>());
  24.                     cities[inputData[0]][inputData[1]].Add(inputData[2]);
  25.                 }
  26.                 else
  27.                 {
  28.                     if (cities[inputData[0]].ContainsKey(inputData[1]) == false)
  29.                     {
  30.                         cities[inputData[0]].Add(inputData[1], new List<string>());
  31.                         cities[inputData[0]][inputData[1]].Add(inputData[2]);
  32.                     }
  33.                     else
  34.                     {
  35.                         cities[inputData[0]][inputData[1]].Add(inputData[2]);
  36.                     }
  37.                 }
  38.                 input = Console.ReadLine();
  39.                 inputData = input.Split(';');
  40.             }
  41.  
  42.             foreach (var town in cities.Keys)
  43.             {
  44.  
  45.                 Console.WriteLine(town);
  46.                 foreach (var item in cities[town].Keys)
  47.                 {
  48.                     Console.WriteLine("->{0}:{1}", item, string.Join(", ", string.Join(", ", cities[town][item])));
  49.                 }
  50.             }
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment