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;
- using System.Threading.Tasks;
- namespace _04.Roli__The_Coder
- {
- public class Event
- {
- public string Name {get; set;}
- public List<string> Participants {get; set;}
- public Event(string name,List<string> participants)
- {
- Name = name;
- Participants = participants;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Regex regex = new Regex(@"^(?<id>\d+)\s*#(?<eventName>\w+)\s*(?<participants>(?:@[a-zA-Z\d'-]+\s*)*)$");
- Dictionary<int, Event> dictEvents = new Dictionary<int, Event>();
- while (true)
- {
- string line = Console.ReadLine();
- if (line == "Time for Code")
- {
- break;
- }
- Match eventMatch = regex.Match(line);
- if (eventMatch.Success == false)
- {
- continue;
- }
- int id = int.Parse(eventMatch.Groups["id"].Value);
- string eventName = eventMatch.Groups["eventName"].Value;
- List<string> participants = eventMatch.Groups["participants"].Value.Split(new[] { ' ' },
- StringSplitOptions.RemoveEmptyEntries).ToList();
- if (dictEvents.ContainsKey(id) == false)
- {
- dictEvents.Add(id, new Event(eventName, participants));
- }
- else if (dictEvents[id].Name == eventName)
- {
- dictEvents[id].Participants.AddRange(participants);
- dictEvents[id].Participants = dictEvents[id].Participants.Distinct().ToList();
- }
- }
- foreach (var e in dictEvents)
- {
- e.Value.Participants = e.Value.Participants.Distinct().ToList();
- }
- var ordered = dictEvents.Select(a => a.Value).OrderByDescending(e => e.Participants.Count).ThenBy(e => e.Name);
- foreach (var e in ordered)
- {
- Console.WriteLine("{0} - {1}",e.Name,e.Participants.Count);
- foreach (var p in e.Participants.OrderBy(p => p))
- {
- Console.WriteLine(p);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement