alexmitev

NightLifeBook

Nov 27th, 2015
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.74 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. class Program
  8. {
  9.     static void PrintTheNightBook(Dictionary<string, SortedDictionary<string, SortedSet<string>>> nightBook) // method to print the nightBook;
  10.     {
  11.         foreach (var town in nightBook)
  12.         {
  13.             Console.WriteLine(town.Key);
  14.             foreach (var clubs in town.Value)
  15.             {
  16.                 Console.Write(" --> {0}: {1}", clubs.Key, string.Join(", ", clubs.Value));
  17.                 Console.WriteLine();
  18.             }        
  19.         }
  20.     }
  21.     static void Main()
  22.     {
  23.         Dictionary<string, SortedDictionary<string, SortedSet<string>>> nightBook = new Dictionary<string, SortedDictionary<string, SortedSet<string>>>();
  24.         string input = Console.ReadLine();
  25.         string city = string.Empty;
  26.         string place = string.Empty;
  27.         string performer = string.Empty;
  28.  
  29.         while (input != "END") //Fill out the NightBook;
  30.         {
  31.             var cityPlacePerformer = new List<string>(input.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries).ToList());
  32.             city = cityPlacePerformer[0];
  33.             place = cityPlacePerformer[1];
  34.             performer = cityPlacePerformer[2];
  35.             if (!nightBook.ContainsKey(city))
  36.             {
  37.                 nightBook[city] = new SortedDictionary<string, SortedSet<string>>();
  38.             }
  39.             if (!nightBook[city].ContainsKey(place))
  40.             {
  41.                 nightBook[city][place] = new SortedSet<string>();
  42.             }
  43.             nightBook[city][place].Add(performer);
  44.             input = Console.ReadLine();
  45.         }
  46.         PrintTheNightBook(nightBook);
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment