Advertisement
EmoRz

User_Logs

Jun 7th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace User_Logs
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string input = Console.ReadLine();
  12.             Dictionary<string, Dictionary<string, int>> usersInfo = new Dictionary<string, Dictionary<string, int>>();
  13.             while (input !="end")
  14.             {
  15.                 var ip = input.Split(new char[] {' ','='}, StringSplitOptions.RemoveEmptyEntries).Skip(1).Take(1).ToList();
  16.                 var userName = input.Split(new char[] { ' ', '=' }, StringSplitOptions.RemoveEmptyEntries).TakeLast(1).ToList();
  17.                 //
  18.                 if (!usersInfo.ContainsKey(userName[0]))
  19.                 {
  20.                     Dictionary<string, int> current = new Dictionary<string, int>();
  21.                     current.Add(ip[0], 0);
  22.                     usersInfo.Add(userName[0], current );
  23.                 }
  24.                 if (!usersInfo[userName[0]].ContainsKey(ip[0]))
  25.                 {
  26.                     usersInfo[userName[0]].Add(ip[0], 0);
  27.                 }
  28.  
  29.                 usersInfo[userName[0]][ip[0]]++;
  30.  
  31.                 input = Console.ReadLine();
  32.             }
  33.             foreach (var item in usersInfo.OrderBy(x => x.Key))
  34.             {
  35.                 Console.WriteLine(item.Key+":");
  36.                 var count = item.Value.Count;
  37.                 foreach (var personalData in item.Value)
  38.                 {
  39.                     count--;
  40.                     if (count>0)
  41.                     {
  42.                         Console.Write(personalData.Key + " => " + personalData.Value + ", ");
  43.                     }
  44.                     else
  45.                     {
  46.  
  47.                         Console.Write(personalData.Key + " => " + personalData.Value + ".");
  48.                     }
  49.                 }
  50.                 Console.WriteLine();
  51.                
  52.  
  53.  
  54.             }
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement