Advertisement
YavorJS

User Logs

Oct 8th, 2016
1,027
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 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.  
  8. class User_Logs
  9. {
  10. static void Main(string[] args)
  11. {
  12. SortedDictionary<string, List<string>> users = new SortedDictionary<string, List<string>>();
  13. string command = "";
  14. while (true)
  15. {
  16. List<string> entry = Console.ReadLine().Split().ToList();
  17. command = entry[0];
  18. if (command == "end") break;
  19. int indexOfIP = command.IndexOf('=') + 1;
  20. string ip = command.Substring(indexOfIP);
  21. int indexOfUser = entry[2].LastIndexOf('=') + 1;
  22. string user = entry[2].Substring(indexOfUser);
  23. List<string> IPs = new List<string>();
  24. IPs.Add(ip);
  25. if (!users.ContainsKey(user))
  26. {
  27. users[user] = IPs;
  28. }
  29. else
  30. {
  31. users[user].AddRange(IPs);
  32. }
  33. }
  34.  
  35. foreach (var user in users)
  36. {
  37. Console.WriteLine(user.Key+": ");
  38. List<string> IPs = user.Value;
  39. Dictionary<string, int> numberOfIPs = new Dictionary<string, int>();
  40. foreach (var ip in IPs)
  41. {
  42. if (!numberOfIPs.ContainsKey(ip))
  43. {
  44. numberOfIPs[ip] = 1;
  45. }
  46. else
  47. {
  48. numberOfIPs[ip]+=1;
  49. }
  50. }
  51.  
  52. int count = numberOfIPs.Count;
  53. foreach (var ip in numberOfIPs)
  54. {
  55. count--;
  56. if (count>0)
  57. {
  58. Console.Write(ip.Key + " => " + ip.Value + ", ");
  59. }
  60. else
  61. {
  62. Console.Write(ip.Key + " => " + ip.Value + ". ");
  63. }
  64. }
  65. Console.WriteLine();
  66.  
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement