Advertisement
Guest User

Untitled

a guest
Sep 21st, 2015
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.80 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _08.Night_Life
  6. {
  7.     class Program
  8.     {
  9.         static void Main()
  10.         {
  11.             var cities = new Dictionary<string, SortedDictionary<string, List<string>>>();
  12.             var venues = new SortedDictionary<string,List<string>>();
  13.             var performers = new List<string>();
  14.             var inputList = new List<string>();                  
  15.             string input = "";
  16.  
  17.             while (input != "END")
  18.             {
  19.                 input = Console.ReadLine();
  20.                
  21.                 if (input.Equals("END"))
  22.                 {                
  23.                     break;
  24.                 }
  25.                 else
  26.                 {
  27.                     inputList = input.Split(';').ToList();
  28.                     string cityStr = inputList[0];
  29.                     string venueStr = inputList[1];
  30.                     string perfStr = inputList[2];
  31.  
  32.                     // Check if city is already in the list.
  33.                     if (cities.ContainsKey(cityStr))
  34.                     {
  35.                         // Check if venue is already in the list for that city.
  36.                         if (cities[cityStr].ContainsKey(venueStr))
  37.                         {
  38.                             // Check if performer is already on the list                        
  39.                             if (!SearchList(cities[cityStr][venueStr], perfStr))
  40.                             {
  41.                                 cities[cityStr][venueStr].Add(perfStr);
  42.                             }
  43.                         }
  44.                         else
  45.                         {                          
  46.                             cities[cityStr].Add(venueStr, performers);
  47.                             performers = new List<string>();
  48.                             cities[cityStr][venueStr].Add(perfStr);
  49.                         }
  50.                     }
  51.                     else
  52.                     {
  53.                         cities.Add(cityStr, venues);
  54.                         venues = new SortedDictionary<string, List<string>>();
  55.                         cities[cityStr].Add(venueStr, performers);
  56.                         performers = new List<string>();
  57.                         cities[cityStr][venueStr].Add(perfStr);
  58.                     }
  59.                 }
  60.             }
  61.  
  62.             // Sort performers alphabetically.
  63.             foreach (var city in cities)
  64.             {              
  65.                 foreach (var venue in city.Value)
  66.                 {
  67.                     (venue.Value).Sort();
  68.                 }              
  69.             }
  70.  
  71.             // Print results.
  72.             foreach (var city in cities)
  73.             {
  74.                 Console.WriteLine(city.Key);
  75.                 foreach (var venue in city.Value)
  76.                 {
  77.                     Console.Write("->{0}: ", venue.Key);
  78.                     for (int i = 0; i < venue.Value.Count;i++)
  79.                     {
  80.                         Console.Write(venue.Value[i]);
  81.                         if (i < venue.Value.Count - 1)
  82.                         {
  83.                             Console.Write(", ");
  84.                         }
  85.                     }
  86.                     Console.WriteLine();
  87.                 }
  88.             }
  89.             Console.WriteLine();
  90.         }
  91.  
  92.         // Check if performer is already on the list.
  93.         static bool SearchList(List<string> list, string item)
  94.         {
  95.             bool check = false;
  96.             string position = "";
  97.             for (int i = 0; i < list.Count; i++)
  98.             {
  99.                 if (list[i].Equals(item))
  100.                 {
  101.                     check = true;
  102.                     position = i.ToString();
  103.                 }
  104.             }
  105.             return check;
  106.         }
  107.     }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement