Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace _13.ActivityTracker
- {
- using System;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- class ActivityTracker
- {
- static void Main(string[] args)
- {
- int linesCount = int.Parse(Console.ReadLine());
- SortedDictionary<int, SortedDictionary<string, int>> monthsActivity = new SortedDictionary<int, SortedDictionary<string, int>>();
- string pattern = @"\d{2}/(\d{2})/\d{4}\s+(\w{1,20})\s+(\d+)";
- for (int i = 0; i < linesCount; i++)
- {
- string input = Console.ReadLine();
- MatchCollection matches = Regex.Matches(input, pattern);
- int month = 0, distance = 0;
- string username = string.Empty;
- foreach (Match match in matches)
- {
- month = int.Parse(match.Groups[1].Value);
- username = match.Groups[2].Value;
- distance = int.Parse(match.Groups[3].Value);
- }
- if (!monthsActivity.ContainsKey(month))
- {
- monthsActivity[month] = new SortedDictionary<string, int>();
- }
- if (!monthsActivity[month].ContainsKey(username))
- {
- monthsActivity[month][username] = 0;
- }
- monthsActivity[month][username] += distance;
- }
- foreach (var monthInfo in monthsActivity)
- {
- Console.Write("{0}: ", monthInfo.Key);
- int count = monthInfo.Value.Count;
- foreach (var userInfo in monthInfo.Value)
- {
- count--;
- Console.Write("{0}({1})", userInfo.Key, userInfo.Value);
- if (count > 0)
- {
- Console.Write(", ");
- }
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement