Advertisement
LardaX

Roli-The-Coder

Oct 26th, 2016
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.89 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Roli_The_Coder
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.  
  15.             char[] delimiters = new char[] { ' ', '@' };
  16.  
  17.             Dictionary<int, string> nameAndId = new Dictionary<int, string>();
  18.             Dictionary<string, List<string>> eventAndNames = new Dictionary<string, List<string>>();
  19.  
  20.             string input = Console.ReadLine();
  21.  
  22.             while (!input.Equals("Time for Code"))
  23.             {
  24.                 string[] inputCommand = input.Split(delimiters, StringSplitOptions.RemoveEmptyEntries).ToArray();
  25.  
  26.                 int id = int.Parse(inputCommand[0]);
  27.                 string eventName = string.Join("", Regex.Split(inputCommand[1], "#"));
  28.                 //     string eventName = input[1].Substring(1);
  29.                 string symbol = inputCommand[1].Substring(0, 1);
  30.  
  31.                 if (symbol == "#")
  32.                 {
  33.  
  34.                     InsertNameAndId(nameAndId, id, eventName, eventAndNames);
  35.                     string[] names = inputCommand.Skip(2).ToArray();
  36.  
  37.                     if (nameAndId.ContainsValue(eventName))
  38.                     {
  39.                         InsertNames(eventAndNames, names, eventName);
  40.                     }
  41.  
  42.                 }
  43.  
  44.                 input = Console.ReadLine();
  45.  
  46.             }
  47.  
  48.             //        Dictionary<string, List<string>> final = new Dictionary<string, List<string>>();
  49.  
  50.             //    foreach (var item in eventAndNames)
  51.             //    {
  52.             //        final.Add(item.Key, item.Value.OrderBy(x => x).ToList());
  53.             //    }
  54.  
  55.             foreach (var eventName in eventAndNames.OrderByDescending(x => x.Value.Count).ThenBy(x => x.Key))
  56.             {
  57.                 Console.WriteLine($"{eventName.Key} - {eventName.Value.Count}");
  58.                 foreach (var guestName in eventName.Value.OrderBy(x => x).Distinct())
  59.                 {
  60.                     Console.WriteLine($"@{guestName}");
  61.                 }
  62.             }
  63.         }
  64.  
  65.         private static void InsertNames(Dictionary<string, List<string>> eventAndNames, string[] names, string eventName)
  66.         {
  67.             foreach (string name in names)
  68.             {
  69.                 if (!eventAndNames[eventName].Contains(name))
  70.                 {
  71.                     eventAndNames[eventName].Add(name);
  72.                 }
  73.             }
  74.         }
  75.  
  76.         private static void InsertNameAndId(Dictionary<int, string> nameAndId, int id, string eventName, Dictionary<string, List<string>> eventAndNames)
  77.         {
  78.             if (!nameAndId.ContainsKey(id))
  79.             {
  80.                 nameAndId.Add(id, eventName);
  81.                 eventAndNames.Add(eventName, new List<string>());
  82.             }
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement