MilenaPetkanova

RoliTheCoder70/100

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