Advertisement
Guest User

Untitled

a guest
Mar 13th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. class Events
  7. {
  8. static void Main()
  9. {
  10. int numberOfEvents = int.Parse(Console.ReadLine());
  11.  
  12. var events = new Dictionary<string, SortedDictionary<string, List<DateTime>>>();
  13.  
  14. string pattern = @"#([A-Za-z]+):\s*@([A-Za-z]+)\s*([0-9]+:[0-9]+)";
  15.  
  16. Regex eventRegex = new Regex(pattern);
  17.  
  18. for (int i = 0; i < numberOfEvents; i++)
  19. {
  20. string venue = Console.ReadLine();
  21.  
  22. if (eventRegex.IsMatch(venue))
  23. {
  24. try
  25. {
  26. Match eventMatch = eventRegex.Match(venue);
  27.  
  28. string person = eventMatch.Groups[1].ToString();
  29. string location = eventMatch.Groups[2].ToString();
  30. DateTime timeOfEvent = DateTime.Parse(eventMatch.Groups[3].ToString());
  31.  
  32. if (!events.ContainsKey(location))
  33. {
  34. events.Add(location, new SortedDictionary<string, List<DateTime>>());
  35. }
  36. if (!events[location].ContainsKey(person))
  37. {
  38. events[location].Add(person, new List<DateTime>());
  39. }
  40.  
  41. events[location][person].Add(timeOfEvent);
  42. }
  43. catch (Exception)
  44. {
  45. continue;
  46. }
  47. }
  48. }
  49.  
  50. List<string> eventsToReport = Console.ReadLine().Split(',').ToList();
  51. eventsToReport.Sort();
  52.  
  53. foreach (var location in eventsToReport)
  54. {
  55. if (events.ContainsKey(location))
  56. {
  57. Console.WriteLine("{0}:", location);
  58.  
  59. int counter = 1;
  60.  
  61. foreach (var pair in events[location])
  62. {
  63. pair.Value.Sort();
  64.  
  65. Console.WriteLine("{0}. {1} -> {2}", counter, pair.Key, string.Join(", ", pair.Value.Select(x => x.ToString("HH:mm")).ToList()));
  66.  
  67. counter++;
  68. }
  69. }
  70. }
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement