Advertisement
Guest User

Untitled

a guest
Oct 9th, 2016
731
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. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace LINQ
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. string input = Console.ReadLine().Trim();
  14.  
  15. var userLogs = new SortedDictionary<string, SortedDictionary<string, int>>();
  16. while (!input.Equals("end"))
  17. {
  18. string[] log = input.Split(new char[] { '=', ' ' }, StringSplitOptions.RemoveEmptyEntries);
  19. string username = log[5];
  20. string IP = log[1];
  21. int counter = 1;
  22.  
  23. if (!userLogs.ContainsKey(username)) userLogs.Add(username, new SortedDictionary<string, int>());
  24. if (!userLogs[username].ContainsKey(IP)) userLogs[username].Add(IP, counter);
  25. else userLogs[username][IP]++;
  26.  
  27. input = Console.ReadLine();
  28. }
  29.  
  30. foreach (var user in userLogs)
  31. {
  32. Console.WriteLine($"{user.Key}: ");
  33. foreach (var log in user.Value)
  34. {
  35. var thing = log.Key;
  36. if (log.Key != user.Value.Keys.Last()) Console.Write($"{log.Key} => {log.Value}, ");
  37. else Console.WriteLine($"{log.Key} => {log.Value}.");
  38. }
  39. }
  40. }
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement