WindFell

User Logs

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