Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- class RoliTheCoder
- {
- static void Main(string[] args)
- {
- var eventAndIdRegex = new Regex(@"^(?<id>\d+)\s+(?<event>#\w+)");
- var participantsRegex = new Regex(@"@(?<participant>[A-Za-z\d\-\']*)");
- var events = new Dictionary<long, Event>();
- while (true)
- {
- string line = Console.ReadLine();
- if (line == "Time for Code")
- break;
- var eventAndIdMatch = eventAndIdRegex.Match(line);
- if (!eventAndIdMatch.Success)
- continue;
- var id = long.Parse(eventAndIdMatch.Groups["id"].Value);
- var eventName = eventAndIdMatch.Groups["event"].Value;
- var participants = participantsRegex.Matches(line).Cast<Match>().Select(p => p.Value.Trim()).ToList();
- if (events.ContainsKey(id))
- {
- if (events[id].EventName == eventName)
- AddParticipants(events, id, participants);
- }
- else
- {
- var @event = new Event(eventName, new HashSet<string>());
- events.Add(id, @event);
- AddParticipants(events, id, participants);
- }
- }
- foreach (var @event in events.OrderByDescending(e => e.Value.Paritcipants.Count).ThenBy(e => e.Value.EventName))
- {
- Console.WriteLine($"{@event.Value.EventName.TrimStart('#')} - {@event.Value.Paritcipants.Count}");
- var participants = @event.Value.Paritcipants;
- foreach (var participant in participants.OrderBy(p => p))
- {
- Console.WriteLine($"{participant}");
- }
- }
- }
- private static void AddParticipants(Dictionary<long, Event> events, long id, List<string> participants)
- {
- foreach (var participant in participants)
- {
- events[id].Paritcipants.Add(participant);
- }
- }
- public class Event
- {
- public Event(string eventName, HashSet<string> paritcipants)
- {
- EventName = eventName;
- Paritcipants = paritcipants;
- }
- public string EventName { get; set; }
- public HashSet<string> Paritcipants { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement