Advertisement
miroLLL

*06Problem-UserLogs

Feb 13th, 2018
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.66 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _06Problem_UserLog
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string[] input = Console.ReadLine().Split(new char[] { '=', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  12.  
  13.             var userLogs = new SortedDictionary<string, Dictionary<string, int>>();
  14.  
  15.             while (!input[0].Equals("end"))
  16.             {
  17.                 string currentIpAddress = input[1];
  18.                 string currentUser = input[input.Length - 1];
  19.  
  20.                 if (userLogs.ContainsKey(currentUser) == false)
  21.                 {
  22.                     userLogs.Add(currentUser, new Dictionary<string, int>());
  23.                     userLogs[currentUser].Add(currentIpAddress, 1);
  24.                 }
  25.                 else
  26.                 {
  27.                     if (userLogs[currentUser].ContainsKey(currentIpAddress) == false)
  28.                     {
  29.                         userLogs[currentUser].Add(currentIpAddress, 1);
  30.                     }
  31.                     else
  32.                     {
  33.                         userLogs[currentUser][currentIpAddress]++;
  34.                     }
  35.                 }
  36.  
  37.                 input = Console.ReadLine().Split(new char[] { '=', ' ' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  38.             }
  39.  
  40.  
  41.             foreach (var kvp in userLogs)
  42.             {
  43.                 Console.WriteLine($"{kvp.Key}: ");
  44.  
  45.                 string[] result = kvp.Value.Select(x => $"{x.Key} => {x.Value}").ToArray();
  46.  
  47.                 Console.WriteLine("{0}.", string.Join(", ", result));
  48.             }
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement