Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- class Events
- {
- static void Main()
- {
- int numberOfEvents = int.Parse(Console.ReadLine());
- var events = new Dictionary<string, SortedDictionary<string, List<DateTime>>>();
- string pattern = @"#([A-Za-z]+):\s*@([A-Za-z]+)\s*([0-9]+:[0-9]+)";
- Regex eventRegex = new Regex(pattern);
- for (int i = 0; i < numberOfEvents; i++)
- {
- string venue = Console.ReadLine();
- if (eventRegex.IsMatch(venue))
- {
- try
- {
- Match eventMatch = eventRegex.Match(venue);
- string person = eventMatch.Groups[1].ToString();
- string location = eventMatch.Groups[2].ToString();
- DateTime timeOfEvent = DateTime.Parse(eventMatch.Groups[3].ToString());
- if (!events.ContainsKey(location))
- {
- events.Add(location, new SortedDictionary<string, List<DateTime>>());
- }
- if (!events[location].ContainsKey(person))
- {
- events[location].Add(person, new List<DateTime>());
- }
- events[location][person].Add(timeOfEvent);
- }
- catch (Exception)
- {
- continue;
- }
- }
- }
- List<string> eventsToReport = Console.ReadLine().Split(',').ToList();
- eventsToReport.Sort();
- foreach (var location in eventsToReport)
- {
- if (events.ContainsKey(location))
- {
- Console.WriteLine("{0}:", location);
- int counter = 1;
- foreach (var pair in events[location])
- {
- pair.Value.Sort();
- Console.WriteLine("{0}. {1} -> {2}", counter, pair.Key, string.Join(", ", pair.Value.Select(x => x.ToString("HH:mm")).ToList()));
- counter++;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement