Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. namespace RoliTheCoder
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text.RegularExpressions;
  7. public class RoliTheCoder
  8. {
  9. static void Main()
  10. {
  11. var dict = new Dictionary<int, Event>();
  12.  
  13.  
  14.  
  15. int id = 0;
  16. string eventName = string.Empty;
  17.  
  18. while (true)
  19. {
  20. string input = Console.ReadLine().TrimStart();
  21. if (input == "Time for Code")
  22. {
  23. break;
  24. }
  25.  
  26. string[] tokens = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  27. string idPattern = @"(?<id>\d+)";
  28. Match firstMatch = Regex.Match(tokens[0], idPattern);
  29. if (firstMatch.Success)
  30. {
  31. id = int.Parse(firstMatch.Groups["id"].Value);
  32. }
  33. string eventPattern = @"#(?<event>.+)";
  34. Match secondMatch = Regex.Match(tokens[1], eventPattern);
  35. if (secondMatch.Success)
  36. {
  37. eventName = secondMatch.Groups["event"].Value;
  38.  
  39. }
  40. else
  41. {
  42. continue;
  43. }
  44. var list = new List<string>();
  45. string thirdPattern = @"@(?<participants>[A-Za-z0-9'-]+)";
  46. MatchCollection matches = Regex.Matches(input, thirdPattern);
  47. foreach (var item in matches)
  48. {
  49. list.Add(item.ToString());
  50.  
  51. }
  52. list.Sort();
  53. if (!dict.ContainsKey(id))
  54. {
  55. list = list.Distinct().ToList();
  56. dict.Add(id, new Event(eventName, id, list));
  57. }
  58. else
  59. {
  60. if (dict[id].Name != eventName)
  61. {
  62. continue;
  63. }
  64. else
  65. {
  66. if (dict[id].Name == eventName)
  67. {
  68. dict[id].Participants.AddRange(list);
  69. dict[id].Participants = dict[id].Participants.Distinct().ToList();
  70. }
  71. }
  72. }
  73.  
  74. }
  75. dict = dict.OrderByDescending(x => x.Value.Participants.Count()).ThenBy(x => x.Value.Name).ToDictionary(x => x.Key, x => x.Value);
  76. foreach (var kvp in dict)
  77. {
  78. //print format - {eventName} – {participantCount}
  79. Console.WriteLine($"{kvp.Value.Name} - {kvp.Value.Participants.Count()}");
  80. foreach (var participant in kvp.Value.Participants.OrderBy(x => x))
  81. {
  82. Console.WriteLine($"{participant}");
  83. }
  84. }
  85.  
  86. }
  87. }
  88. public class Event
  89. {
  90. public string Name { get; set; }
  91.  
  92. public int Id { get; set; }
  93.  
  94. public List<string> Participants { get; set; }
  95.  
  96. public Event(string name, int id, List<string> participants)
  97. {
  98. this.Name = name;
  99. this.Id = id;
  100. this.Participants = participants;
  101. }
  102. }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement