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;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace rolicoder
- {
- class Program
- {
- class Event
- {
- public string Name { get; set; }
- public List<string> Participants { get; set; }
- public Event(string name, List<string> participants)
- {
- Name = name;
- Participants = participants;
- }
- }
- static void Main(string[] args)
- {
- Dictionary<long, Event> events = new Dictionary<long, Event>();
- string input = Console.ReadLine();
- string pattern = @"^(?<id>[\d]+) #(?<name>[\w]+)(?<participants>[ ?@\w]*)$";
- while (input != "Time for Code")
- {
- Match currMatch = Regex.Match(input, pattern);
- long id = long.Parse(currMatch.Groups["id"].Value);
- string eventName = currMatch.Groups["name"].Value;
- List<string> participants = new List<string>(currMatch.Groups["participants"].Value
- .Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)
- .ToList());
- if (!events.ContainsKey(id))
- {
- events.Add(id, new Event(eventName, participants));
- }
- else
- {
- if (events[id].Name == eventName)
- {
- for (int i = 0; i < participants.Count; i++)
- {
- if (!events[id].Participants.Contains(participants[i]))
- {
- events[id].Participants.Add(participants[i]);
- }
- }
- }
- }
- input = Console.ReadLine();
- }
- var orderedEvents = events
- .OrderByDescending(oe => oe.Value.Participants.Count())
- .ThenBy(oe => oe.Value.Name);
- foreach (var orderedEvent in orderedEvents)
- {
- Console.WriteLine("{0} - {1}", orderedEvent.Value.Name, orderedEvent.Value.Participants.Count());
- foreach (var participant in orderedEvent.Value.Participants.OrderBy(oe => oe))
- {
- Console.WriteLine(participant);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement