Advertisement
sivancheva

RoliTheCoder

Oct 2nd, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.20 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace _04_RoliTheCoder
  9. {
  10. class RoliTheCoder
  11. {
  12. static void Main(string[] args)
  13. {
  14. var input = Console.ReadLine();
  15. var eventsDict = new Dictionary<int, string>();
  16. var resultDict = new Dictionary<string, List<string>>();
  17. var patterParticipantName = new Regex(@"^@[a-zA-Z\d+'-]+$");
  18.  
  19. while (input != "Time for Code")
  20. {
  21. var inputArray = input.Split(new[] { ' '}, StringSplitOptions.RemoveEmptyEntries)
  22. .Select(x => x.Trim()).ToArray();
  23.  
  24. if (inputArray.Length < 2)
  25. {
  26. input = Console.ReadLine();
  27. continue;
  28. }
  29. int eventId = 0;
  30. try
  31. {
  32. eventId = int.Parse(inputArray[0]);
  33. }
  34. catch
  35. {
  36. input = Console.ReadLine();
  37. continue;
  38. }
  39. if (inputArray[1][0] != '#')
  40. {
  41. input = Console.ReadLine();
  42. continue;
  43. }
  44. string eventName = inputArray[1].Substring(1, inputArray[1].Length - 1);
  45.  
  46. var participantsList = new List<string>();
  47.  
  48.  
  49. for (int i = 2; i < inputArray.Length; i++)
  50. {
  51. var matchedParticipantName = patterParticipantName.Match(inputArray[i]);
  52. if (matchedParticipantName.Success)
  53. {
  54. participantsList.Add(inputArray[i]);
  55. }
  56.  
  57. }
  58. if (!eventsDict.ContainsKey(eventId))
  59. {
  60. eventsDict[eventId] = eventName;
  61.  
  62. resultDict.Add(eventName, new List<string>());
  63.  
  64. for (int i = 0; i < participantsList.Count; i++)
  65. {
  66. resultDict[eventName].Add(participantsList[i]);
  67. }
  68. }
  69. else if (eventsDict.ContainsKey(eventId) && eventsDict[eventId] == eventName)
  70. {
  71. for (int i = 0; i < participantsList.Count; i++)
  72. {
  73. resultDict[eventName].Add(participantsList[i]);
  74. }
  75. }
  76.  
  77.  
  78. input = Console.ReadLine();
  79. }
  80.  
  81.  
  82. var sortedDict = resultDict
  83. .OrderByDescending(a => a.Value.Distinct().Count())
  84. .ThenBy(a => a.Value)
  85. .ToList();
  86.  
  87. foreach (var item in sortedDict)
  88. {
  89. Console.WriteLine($"{item.Key} - {item.Value.Distinct().Count()}");
  90.  
  91. foreach (var participant in item.Value.Distinct().OrderBy(a => a))
  92. {
  93. Console.WriteLine($"{participant}");
  94. }
  95.  
  96. }
  97.  
  98. }
  99. }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement