Advertisement
Rayk

Untitled

Nov 3rd, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. class RoliTheCoder
  7. {
  8. static void Main(string[] args)
  9. {
  10. var eventAndIdRegex = new Regex(@"^(?<id>\d+)\s+(?<event>#\w+)");
  11. var participantsRegex = new Regex(@"@(?<participant>[A-Za-z\d\-\']*)");
  12.  
  13. var events = new Dictionary<long, Event>();
  14.  
  15. while (true)
  16. {
  17. string line = Console.ReadLine();
  18. if (line == "Time for Code")
  19. break;
  20.  
  21. var eventAndIdMatch = eventAndIdRegex.Match(line);
  22. if (!eventAndIdMatch.Success)
  23. continue;
  24.  
  25. var id = long.Parse(eventAndIdMatch.Groups["id"].Value);
  26. var eventName = eventAndIdMatch.Groups["event"].Value;
  27. var participants = participantsRegex.Matches(line).Cast<Match>().Select(p => p.Value.Trim()).ToList();
  28.  
  29. if (events.ContainsKey(id))
  30. {
  31. if (events[id].EventName == eventName)
  32. AddParticipants(events, id, participants);
  33. }
  34. else
  35. {
  36. var @event = new Event(eventName, new HashSet<string>());
  37. events.Add(id, @event);
  38. AddParticipants(events, id, participants);
  39. }
  40. }
  41.  
  42. foreach (var @event in events.OrderByDescending(e => e.Value.Paritcipants.Count).ThenBy(e => e.Value.EventName))
  43. {
  44. Console.WriteLine($"{@event.Value.EventName.TrimStart('#')} - {@event.Value.Paritcipants.Count}");
  45. var participants = @event.Value.Paritcipants;
  46. foreach (var participant in participants.OrderBy(p => p))
  47. {
  48. Console.WriteLine($"{participant}");
  49. }
  50. }
  51. }
  52.  
  53. private static void AddParticipants(Dictionary<long, Event> events, long id, List<string> participants)
  54. {
  55. foreach (var participant in participants)
  56. {
  57. events[id].Paritcipants.Add(participant);
  58. }
  59. }
  60.  
  61. public class Event
  62. {
  63. public Event(string eventName, HashSet<string> paritcipants)
  64. {
  65. EventName = eventName;
  66. Paritcipants = paritcipants;
  67. }
  68.  
  69. public string EventName { get; set; }
  70.  
  71. public HashSet<string> Paritcipants { get; set; }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement