Advertisement
StoyanGrigorov

Roli the Drug Addict

Oct 24th, 2016
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Text.RegularExpressions;
  7. //04. Roli The Coder
  8. namespace RoliTheCoder
  9. {
  10. class RoliTheCoder
  11. {
  12. static void Main(string[] args)
  13. {
  14. Dictionary<int, string> eventsIds = new Dictionary<int, string>();
  15. Dictionary<string, List<string>> events = new Dictionary<string, List<string>>();
  16.  
  17.  
  18. string pattern = @"([0-9]+)\s+#\s*(\w+)\s*";
  19.  
  20. Regex rgx1 = new Regex(pattern);
  21. string command = Console.ReadLine();
  22.  
  23. while (command != "Time for Code")
  24. {
  25. if (rgx1.IsMatch(command))
  26. {
  27. Match match = rgx1.Match(command);
  28. int ID = int.Parse(match.Groups[1].Value.Trim());
  29. string eventName = match.Groups[2].Value.Trim();
  30. string temp = Regex.Replace(command, @"\s+", "");
  31. List<string> people = new List<string>();
  32. if (temp.Contains("@"))
  33. {
  34. int startIndex = temp.IndexOf('@');
  35. temp = temp.Substring(startIndex);
  36. people = temp.Split(new char[] { '@' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  37. }
  38.  
  39. if (eventsIds.ContainsKey(ID))
  40. {
  41. if (eventsIds[ID] == eventName)
  42. {
  43. if (events.ContainsKey(eventName))
  44. {
  45. events[eventName].AddRange(people);
  46. }
  47. else
  48. {
  49. events.Add(eventName, people);
  50. }
  51. }
  52. }
  53. else
  54. {
  55. eventsIds.Add(ID, eventName);
  56. events.Add(eventName, people);
  57. }
  58. }
  59. command = Console.ReadLine();
  60. }
  61.  
  62.  
  63. foreach (var eve in events.OrderByDescending(x => x.Value.Count).ThenBy(z => z.Key))
  64. {
  65. Console.WriteLine($"{eve.Key} - {eve.Value.Distinct().Count()}");
  66. foreach (var person in eve.Value.Distinct().OrderBy(x => x))
  67. {
  68. Console.WriteLine($"@{person}");
  69. }
  70. }
  71. }
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement