MilenaPetkanova

RoliTheCoder80/100

Nov 3rd, 2017
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 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()
  9. {
  10. var idsAndEvents = new Dictionary<string, string>();
  11.  
  12. var eventsAndParticipants = new SortedDictionary<string,
  13. SortedSet<string>>();
  14.  
  15. string input = Console.ReadLine();
  16. while (input != "Time for Code")
  17. {
  18. if (!Regex.IsMatch(input, @"(?<id>\d+)\s+#(?<event>\w+)(?<prtcpnts>((?:\s+@\w+)+)?)"))
  19. {
  20. input = Console.ReadLine();
  21. continue;
  22. }
  23.  
  24. var inputArgs = input.Split(new char[] {' ', '\t', '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  25.  
  26. if (!Regex.IsMatch(inputArgs[1], @"#\w+"))
  27. {
  28. input = Console.ReadLine();
  29. continue;
  30. }
  31.  
  32. string id = inputArgs[0];
  33. string eventName = inputArgs[1].Remove(0, 1).ToString();
  34.  
  35. if (idsAndEvents.ContainsKey(id) && !idsAndEvents.ContainsValue(eventName))
  36. {
  37. input = Console.ReadLine();
  38. continue;
  39. }
  40.  
  41. SortedSet<string> participants = new SortedSet<string>();
  42.  
  43. if (inputArgs.Length > 2)
  44. {
  45. for (int i = 2; i < inputArgs.Length; i++)
  46. {
  47. participants.Add(inputArgs[i].ToString());
  48. }
  49. }
  50.  
  51. if (!eventsAndParticipants.ContainsKey(eventName))
  52. {
  53. idsAndEvents.Add(id, eventName);
  54. eventsAndParticipants.Add(eventName, new SortedSet<string>());
  55. eventsAndParticipants[eventName].UnionWith(participants);
  56. }
  57. else
  58. {
  59. eventsAndParticipants[eventName].UnionWith(participants);
  60. }
  61.  
  62. input = Console.ReadLine();
  63. }
  64.  
  65. var sortedEvents = new Dictionary<string, int>();
  66. foreach (var ev in eventsAndParticipants)
  67. {
  68. sortedEvents.Add(ev.Key, ev.Value.Count);
  69. }
  70.  
  71. foreach (var evnt in sortedEvents.OrderByDescending(x => x.Value))
  72. {
  73. Console.WriteLine($"{evnt.Key} - {evnt.Value}");
  74.  
  75. var participants = eventsAndParticipants
  76. .Where(x => x.Key == evnt.Key)
  77. .ToDictionary(x => x.Key, y => y.Value);
  78.  
  79. foreach (var participant in participants.Values)
  80. {
  81. foreach (var p in participant)
  82. {
  83. Console.WriteLine($"{p}");
  84.  
  85. }
  86. }
  87. }
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment