Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace RoliTheCoder
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- public class RoliTheCoder
- {
- static void Main()
- {
- var dict = new Dictionary<int, Event>();
- int id = 0;
- string eventName = string.Empty;
- while (true)
- {
- string input = Console.ReadLine().TrimStart();
- if (input == "Time for Code")
- {
- break;
- }
- string[] tokens = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- string idPattern = @"(?<id>\d+)";
- Match firstMatch = Regex.Match(tokens[0], idPattern);
- if (firstMatch.Success)
- {
- id = int.Parse(firstMatch.Groups["id"].Value);
- }
- string eventPattern = @"#(?<event>.+)";
- Match secondMatch = Regex.Match(tokens[1], eventPattern);
- if (secondMatch.Success)
- {
- eventName = secondMatch.Groups["event"].Value;
- }
- else
- {
- continue;
- }
- var list = new List<string>();
- string thirdPattern = @"@(?<participants>[A-Za-z0-9'-]+)";
- MatchCollection matches = Regex.Matches(input, thirdPattern);
- foreach (var item in matches)
- {
- list.Add(item.ToString());
- }
- list.Sort();
- if (!dict.ContainsKey(id))
- {
- list = list.Distinct().ToList();
- dict.Add(id, new Event(eventName, id, list));
- }
- else
- {
- if (dict[id].Name != eventName)
- {
- continue;
- }
- else
- {
- if (dict[id].Name == eventName)
- {
- dict[id].Participants.AddRange(list);
- dict[id].Participants = dict[id].Participants.Distinct().ToList();
- }
- }
- }
- }
- dict = dict.OrderByDescending(x => x.Value.Participants.Count()).ThenBy(x => x.Value.Name).ToDictionary(x => x.Key, x => x.Value);
- foreach (var kvp in dict)
- {
- //print format - {eventName} – {participantCount}
- Console.WriteLine($"{kvp.Value.Name} - {kvp.Value.Participants.Count()}");
- foreach (var participant in kvp.Value.Participants.OrderBy(x => x))
- {
- Console.WriteLine($"{participant}");
- }
- }
- }
- }
- public class Event
- {
- public string Name { get; set; }
- public int Id { get; set; }
- public List<string> Participants { get; set; }
- public Event(string name, int id, List<string> participants)
- {
- this.Name = name;
- this.Id = id;
- this.Participants = participants;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement