Advertisement
Spaskich

Untitled

Sep 21st, 2015
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.48 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class NightLife
  5. {
  6.     static void Main()
  7.     {
  8.         Dictionary<string, SortedDictionary<string, SortedSet<string>>> performances = new Dictionary<string, SortedDictionary<string, SortedSet<string>>>();
  9.  
  10.         string input = Console.ReadLine();
  11.  
  12.         while (input != "END")
  13.         {
  14.             string[] cityVenuePerformer = input.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
  15.             string city = cityVenuePerformer[0];
  16.             string venue = cityVenuePerformer[1];
  17.             string performer = cityVenuePerformer[2];
  18.  
  19.             if (!performances.ContainsKey(city))
  20.             {
  21.                 performances[city] = new SortedDictionary<string, SortedSet<string>>();
  22.             }
  23.             if (!performances[city].ContainsKey(venue))
  24.             {
  25.                 performances[city][venue] = new SortedSet<string>();
  26.             }
  27.             if (!performances[city][venue].Contains(performer))
  28.             {
  29.                 performances[city][venue].Add(performer);
  30.             }
  31.  
  32.             input = Console.ReadLine();
  33.         }
  34.  
  35.         foreach (var cityVenue in performances)
  36.         {
  37.             Console.WriteLine($"\r\n{cityVenue.Key}");
  38.  
  39.             foreach (var venueWithPerformers in cityVenue.Value)
  40.             {
  41.                 Console.WriteLine("->{0}: {1}", venueWithPerformers.Key, string.Join(", ", venueWithPerformers.Value));
  42.             }
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement