AleksandarKostadinov

06.UsersLog

Feb 4th, 2017
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 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 Log
  8.     {
  9.         public static void Main()
  10.         {
  11.             var tokes = Console.ReadLine()
  12.                 .Split();
  13.             var users = new SortedDictionary<string, Dictionary<string, int>>();
  14.  
  15.             while (tokes[0] != "end")
  16.             {
  17.                 var userThird = tokes[2]
  18.                     .Split('=');
  19.                 var userName = userThird[1];
  20.  
  21.                 if (!users.ContainsKey(userName))
  22.                 {
  23.                     users[userName] = new Dictionary<string, int>();
  24.                 }
  25.  
  26.                 var IPThird = tokes[0].Split('=');
  27.                 var IP = IPThird[1];
  28.  
  29.                 if (!users[userName].ContainsKey(IP))
  30.                 {
  31.                     users[userName][IP] = 0;
  32.                 }
  33.  
  34.                 users[userName][IP]++;
  35.  
  36.                 tokes = Console.ReadLine().Split(' ');
  37.             }
  38.  
  39.             foreach (var user in users)
  40.             {
  41.                 Console.WriteLine(user.Key + ":");
  42.  
  43.                 var output = new List<string>();
  44.  
  45.                 foreach (var ip in user.Value)
  46.                 {
  47.                     output.Add(ip.Key + " => " + ip.Value);
  48.                 }
  49.  
  50.                 Console.WriteLine(string.Join(", ", output) + ".");
  51.             }
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment