Advertisement
sivancheva

LogsAgregator

Aug 31st, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace LogsAggregator
  6. {
  7. class Program
  8. {
  9. public static void Main(string[] args)
  10. {
  11. int n = int.Parse(Console.ReadLine());
  12. //var input = Console.ReadLine().Split(' ').ToArray();
  13. var logsAgregator = new SortedDictionary<string, SortedDictionary<string,int>>();
  14.  
  15.  
  16. for (int i = 0; i < n; i++)
  17. {
  18. var input = Console.ReadLine().Split(' ').ToArray();
  19. string user = input[1];
  20. int duration = int.Parse(input[2]);
  21. string ip = input[0];
  22.  
  23.  
  24.  
  25. if (logsAgregator.ContainsKey(user))
  26. {
  27. if (logsAgregator[user].ContainsKey(ip))
  28. {
  29. logsAgregator[user][ip] += duration;
  30. }
  31. else
  32. {
  33. logsAgregator[user].Add(ip, duration);
  34. }
  35. }
  36. else
  37. {
  38. logsAgregator.Add(user, new SortedDictionary<string, int> {{ip, duration}});
  39. }
  40. }
  41.  
  42.  
  43.  
  44. foreach (var userName in logsAgregator)
  45. {
  46. var name = userName.Key;
  47.  
  48. var ipsDuration = userName.Value; //TOVA E DICT
  49.  
  50. var totalDuration = ipsDuration.Sum(y=>y.Value);
  51.  
  52. var ipsTotal = ipsDuration.Select(y=>y.Keys).ToList();
  53. }
  54.  
  55.  
  56. Console.WriteLine("{0}: {1} ")
  57.  
  58. Console.Write("Press any key to continue . . . ");
  59. Console.ReadKey(true);
  60. }
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement