Advertisement
Ivakis

Untitled

Jun 22nd, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 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 Uprajnenie
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. var dic = new SortedDictionary<string, Dictionary<string, int>>(); // user, ip, count
  14.  
  15.  
  16. while (true)
  17. {
  18. var input = Console.ReadLine().Split();
  19.  
  20. if (input[0] == "end")
  21. {
  22. break;
  23. }
  24.  
  25. var ip = input[0].Replace("IP=","");
  26. var user = input[2].Replace("user=", "");
  27.  
  28. if (!dic.ContainsKey(user))
  29. {
  30. dic.Add(user, new Dictionary<string, int>());
  31. }
  32. if (!dic[user].ContainsKey(ip))
  33. {
  34. dic[user].Add(ip, 0);
  35. }
  36.  
  37. dic[user][ip] = dic[user][ip] + 1; // dic[ip][user] += 1
  38.  
  39. }
  40.  
  41. foreach (KeyValuePair<string, Dictionary<string, int>> item in dic) // user
  42. {
  43.  
  44. Console.WriteLine($"{item.Key}: ");
  45.  
  46. StringBuilder sb = new StringBuilder();
  47.  
  48. foreach (KeyValuePair<string, int> count in item.Value) // ip, count
  49. {
  50. sb.Append(count.Key + " => " + count.Value + ", ");
  51. }
  52.  
  53. sb.Remove(sb.Length - 2, 2);
  54. sb.Append(".");
  55.  
  56. Console.WriteLine(sb);
  57. }
  58.  
  59. }
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement