Advertisement
dimipan80

Night Life

May 10th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.18 KB | None | 0 0
  1. /* You'll receive the input from the console. There will be an arbitrary number of lines until you receive the string "END". Each line will contain data in format: "city;venue;performer". If either city, venue or performer don't exist yet in the database, add them. If either the city and/or venue already exist, update their info.
  2.  * Cities should remain in the order in which they were added, venues should be sorted alphabetically and performers should be unique (per venue) and also sorted alphabetically.
  3.  * Print the data by listing the cities and for each city its venues (on a new line starting with "->") and performers (separated by comma and space). */
  4.  
  5. namespace _08.NightLife
  6. {
  7.     using System;
  8.     using System.Collections.Generic;
  9.  
  10.     class NightLife
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             var dataList = new Dictionary<string, SortedDictionary<string, SortedSet<string>>>();
  15.  
  16.             string inputLine = Console.ReadLine().Trim();
  17.             while (inputLine != "END")
  18.             {
  19.                 string[] temp = inputLine.Split(';');
  20.                 string city = temp[0].Trim();
  21.                 string venue = temp[1].Trim();
  22.                 string performer = temp[2].Trim();
  23.                 if (!dataList.ContainsKey(city))
  24.                 {
  25.                     dataList[city] = new SortedDictionary<string, SortedSet<string>>();
  26.                 }
  27.  
  28.                 if (!dataList[city].ContainsKey(venue))
  29.                 {
  30.                     dataList[city][venue] = new SortedSet<string>();
  31.                 }
  32.  
  33.                 dataList[city][venue].Add(performer);
  34.  
  35.                 inputLine = Console.ReadLine().Trim();
  36.             }
  37.  
  38.             PrintResults(dataList);
  39.         }
  40.  
  41.         private static void PrintResults(Dictionary<string, SortedDictionary<string, SortedSet<string>>> dataList)
  42.         {
  43.             foreach (var entry in dataList)
  44.             {
  45.                 Console.WriteLine(entry.Key);
  46.                 foreach (var pair in entry.Value)
  47.                 {
  48.                     Console.WriteLine("->{0}: {1}", pair.Key, string.Join(", ", pair.Value));
  49.                 }
  50.             }
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement