Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* 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.
- * 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.
- * 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). */
- namespace _08.NightLife
- {
- using System;
- using System.Collections.Generic;
- class NightLife
- {
- static void Main(string[] args)
- {
- var dataList = new Dictionary<string, SortedDictionary<string, SortedSet<string>>>();
- string inputLine = Console.ReadLine().Trim();
- while (inputLine != "END")
- {
- string[] temp = inputLine.Split(';');
- string city = temp[0].Trim();
- string venue = temp[1].Trim();
- string performer = temp[2].Trim();
- if (!dataList.ContainsKey(city))
- {
- dataList[city] = new SortedDictionary<string, SortedSet<string>>();
- }
- if (!dataList[city].ContainsKey(venue))
- {
- dataList[city][venue] = new SortedSet<string>();
- }
- dataList[city][venue].Add(performer);
- inputLine = Console.ReadLine().Trim();
- }
- PrintResults(dataList);
- }
- private static void PrintResults(Dictionary<string, SortedDictionary<string, SortedSet<string>>> dataList)
- {
- foreach (var entry in dataList)
- {
- Console.WriteLine(entry.Key);
- foreach (var pair in entry.Value)
- {
- Console.WriteLine("->{0}: {1}", pair.Key, string.Join(", ", pair.Value));
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement