Advertisement
Guest User

Untitled

a guest
Feb 14th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. namespace _06.UserLogs
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6.  
  7. public class StartUp
  8. {
  9. public static void Main()
  10. {
  11. string input = Console.ReadLine().Trim();
  12.  
  13.  
  14. var usersIPs = new SortedDictionary<string, Dictionary<string, int>>();
  15. while (input!="end")
  16. {
  17. var log = input.Split(new char[] { ' ', '=' }, StringSplitOptions.RemoveEmptyEntries);
  18. var ipAdress = log[1];
  19. var userName = log[5];
  20. var couter = 1;
  21. if (!usersIPs.ContainsKey(userName))
  22. {
  23. usersIPs.Add(userName, new Dictionary<string, int>());
  24. }
  25. if (!usersIPs[userName].ContainsKey(ipAdress))
  26. {
  27. usersIPs[userName].Add(ipAdress, couter);
  28. }
  29. else
  30. {
  31. usersIPs[userName][ipAdress]++;
  32. }
  33. input = Console.ReadLine();
  34. }
  35. foreach (var user in usersIPs)
  36. {
  37. Console.WriteLine($"{user.Key}:");
  38. foreach (var key in user.Value)
  39. {
  40. if (key.Key!=user.Value.Keys.Last())
  41. {
  42. Console.Write($" {key} => {key.Value}, ");
  43. }
  44. else
  45. {
  46. Console.Write($" {key} => {key.Value}.");
  47. }
  48. }
  49. }
  50. Console.WriteLine();
  51. }
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement