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;
- namespace _02_04_RoliTheCoder
- {
- class RoliTheCoder
- {
- static void Main(string[] args)
- {
- Regex pattern = new Regex(@"(?<id>\d+)\s+#(?<event>.+?)($|(?=\ ))");
- Regex participantsPattern = new Regex(@"@[a-zA-Z0-9'-]+");
- Dictionary<int, Event> events = new Dictionary<int, Event>();
- string input = string.Empty;
- while ((input = Console.ReadLine()) != "Time for Code")
- {
- Match match = pattern.Match(input);
- if (match.Success)
- {
- int id = int.Parse(match.Groups["id"].Value);
- string name = match.Groups["event"].Value;
- if (events.ContainsKey(id) && events[id].Name != name)
- {
- continue;
- }
- else if (!events.ContainsKey(id))
- {
- events.Add(id, new Event(name));
- }
- MatchCollection matches = participantsPattern.Matches(input);
- List<string> participants = new List<string>();
- foreach (Match m in matches)
- {
- participants.Add(m.Value);
- }
- events[id].AddParticipants(participants);
- }
- }
- foreach (var pair in events.OrderByDescending(x => x.Value.Participants.Count).ThenBy(x => x.Value.Name))
- {
- Console.WriteLine($"{pair.Value.Name} - {pair.Value.Participants.Count}");
- foreach (string participant in pair.Value.Participants.OrderBy(x => x))
- {
- Console.WriteLine(participant);
- }
- }
- }
- }
- class Event
- {
- public string Name { get; private set; }
- public HashSet<string> Participants;
- public Event(string name)
- {
- this.Participants = new HashSet<string>();
- this.Name = name;
- }
- public void AddParticipants(List<string> participants)
- {
- foreach (string participant in participants)
- {
- this.Participants.Add(participant);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement