Advertisement
Guest User

logs agregator

a guest
Jun 8th, 2016
482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace LogsAgregator
  6. {
  7. public class LogsAggregator
  8. {
  9. static void Main(string[] args)
  10. {
  11. SortedDictionary<string, SortedDictionary<string, int>> data =
  12. new SortedDictionary<string, SortedDictionary<string, int>>();
  13.  
  14. int n = int.Parse(Console.ReadLine());
  15.  
  16. for (int i = 0; i < n; i++)
  17. {
  18. string[] logsInfo = Console.ReadLine().Split();
  19. string ip = logsInfo[0];
  20. string user = logsInfo[1];
  21. int duration = int.Parse(logsInfo[2]);
  22.  
  23. if (!data.ContainsKey(user))
  24. {
  25. data.Add(user, new SortedDictionary<string, int>());
  26. }
  27. if (!data[user].ContainsKey(ip))
  28. {
  29. data[user][ip] = 0;
  30. }
  31.  
  32. data[user][ip] +=duration;
  33. }
  34.  
  35. foreach (var outerPair in data)
  36. {
  37. var sum = outerPair.Value.Values.Sum();
  38.  
  39. Console.Write("{0}: {1} ", outerPair.Key, sum);
  40. Console.Write("[");
  41. Console.Write(string.Join(", ", outerPair.Value.Keys));
  42. Console.WriteLine("]");
  43. }
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement