_CodeBehind

8_Night_Life

Feb 17th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class NightLife
  5. {
  6.     public static void Main()
  7.     {
  8.         var data =new Dictionary<string, SortedDictionary<string, SortedSet<string>>>();
  9.  
  10.         string line = Console.ReadLine();
  11.  
  12.         string[] input;
  13.         string city = String.Empty;
  14.         string venue = String.Empty;
  15.         string performer = String.Empty;
  16.  
  17.         while (line != "END")
  18.         {
  19.             input = line.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
  20.  
  21.             city = input[0];
  22.             venue = input[1];
  23.             performer = input[2];
  24.  
  25.             if (!data.ContainsKey(city)) // проверяваш дали го има този град,ако го няма го добавяш
  26.             {
  27.                 data[city] = new SortedDictionary<string, SortedSet<string>>();
  28.             }
  29.             if (!data[city].ContainsKey(venue)) // проверяваш дали градът съдържа авенюто, ако го няма го добавяш
  30.             {
  31.                 data[city][venue] = new SortedSet<string>();
  32.             }
  33.             data[city][venue].Add(performer); //добавяш участника , понеже си със хаш сетове , те пазят само уникалните стойности
  34.  
  35.             line = Console.ReadLine();
  36.         }
  37.  
  38.         foreach (var cityPair in data)
  39.         {
  40.             Console.WriteLine(cityPair.Key);
  41.             foreach (var venuePair in cityPair.Value)
  42.             {
  43.                 Console.WriteLine("->{0}: {1}", venuePair.Key, String.Join(", ", venuePair.Value));
  44.             }
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment