Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _08._Logs_Aggregator
- {
- class Program
- {
- static void Main(string[] args)
- {
- int numOfLogs = int.Parse(Console.ReadLine());
- SortedDictionary<string, SortedDictionary<string, int>> dictOfUsers = new SortedDictionary<string, SortedDictionary<string, int>>();
- for (int i = 0; i < numOfLogs; i++)
- {
- var userInfo = Console.ReadLine().Split().ToArray();
- string IP = userInfo[0];
- string username = userInfo[1];
- int duration = int.Parse(userInfo[2]);
- if (!dictOfUsers.ContainsKey(username))
- {
- dictOfUsers.Add(username, new SortedDictionary<string, int>());
- }
- if (!dictOfUsers[username].ContainsKey(IP))
- {
- dictOfUsers[username].Add(IP, duration);
- }
- else
- {
- dictOfUsers[username][IP] += duration;
- }
- }
- foreach (var user in dictOfUsers)
- {
- var totalDurationOfUser = dictOfUsers[user.Key].Values.Sum();
- var listOfIps = user.Value.Keys.ToList();
- Console.WriteLine($"{user.Key}: {totalDurationOfUser} [{string.Join(", ", listOfIps)}]");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement