Advertisement
Guest User

Untitled

a guest
Oct 15th, 2017
772
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ConsoleApp4
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. var numOfLogs = int.Parse(Console.ReadLine());
  12. var dictOfUsers = new SortedDictionary<string, SortedDictionary<string, int>>();
  13. for (int i = 0; i < numOfLogs; i++)
  14. {
  15. var userInfo = Console.ReadLine().Split().ToArray();
  16. var IP = userInfo[0];
  17. var username = userInfo[1];
  18. var duration = int.Parse(userInfo[2]);
  19. if (!dictOfUsers.ContainsKey(username))
  20. {
  21. dictOfUsers.Add(username, new SortedDictionary<string, int>());
  22. }
  23. if (!dictOfUsers[username].ContainsKey(IP))
  24. {
  25. dictOfUsers[username].Add(IP, duration);
  26. }
  27. else
  28. {
  29. dictOfUsers[username][IP] += duration;
  30. }
  31.  
  32. }
  33.  
  34. foreach (var user in dictOfUsers)
  35. {
  36. var totalDurationOfUser = dictOfUsers[user.Key].Values.Sum();
  37. var listOfIps = user.Value.Keys.ToList();
  38. Console.WriteLine($"{user.Key}: {totalDurationOfUser} [{string.Join(", ", listOfIps)}]");
  39. }
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement