Skip to content

Instantly share code, notes, and snippets.

@Tuscann
Created November 4, 2017 22:44
Show Gist options
  • Save Tuscann/e2a2ab0d67e551411c2203624c988aec to your computer and use it in GitHub Desktop.
Save Tuscann/e2a2ab0d67e551411c2203624c988aec to your computer and use it in GitHub Desktop.
04. Roli The Coder
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
class Program
{
static void Main()
{
Dictionary<int, List<string>> eventNamesParticipants = new Dictionary<int, List<string>>();
while (true)
{
List<string> input = Console.ReadLine().Split(' ').Select(data => data.Trim()).ToList();
if (input[0] == "Time")
{
break;
}
if (!CheckValidity(input))
{
int id = int.Parse(input[0]);
string eventName = input[1].Substring(1);
if (!eventNamesParticipants.ContainsKey(id))
{
eventNamesParticipants.Add(id, new List<string>());
eventNamesParticipants[id].Add(eventName);
for (int i = 2; i < input.Count; i++)
{
eventNamesParticipants[id].Add(input[i]);
}
}
if (eventNamesParticipants[id][0] == eventName)
{
for (int i = 2; i < input.Count; i++)
{
eventNamesParticipants[id].Add(input[i]);
}
}
eventNamesParticipants[id] = eventNamesParticipants[id].Distinct().ToList();
}
}
foreach (var events in eventNamesParticipants.OrderByDescending(participants => participants.Value.Count).ThenBy(events => events.Value[0]))
{
Console.WriteLine($"{events.Value[0]} - {events.Value.Count - 1}");
foreach (var participant in events.Value.OrderBy(name => name))
{
if (participant.StartsWith("@"))
{
Console.WriteLine(participant);
}
}
}
}
static bool CheckValidity(List<string> input)
{
if (!input[1].StartsWith("#"))
{
return true;
}
for (int i = 2; i < input.Count; i++)
{
Match match = Regex.Match(input[i], @"^@[a-zA-Z-'0-9]+$");
if (!match.Success)
{
return true;
}
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment