Advertisement
bacco

User Logs

Jun 15th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.70 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace user-Logs
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.            var userHolder = new SortedDictionary<string, Dictionary<string, int>>();
  12.  
  13.             while (true)
  14.             {
  15.                 var input = Console.ReadLine().Split()
  16.                                               .ToList();
  17.  
  18.                 if (input[0].Equals("end"))
  19.                 {
  20.                     break;
  21.                 }
  22.  
  23.                 var ipS  = input[0].Substring(3);
  24.                 var user = input[2].Substring(5);
  25.  
  26.  
  27.                 if (!userHolder.ContainsKey(user))
  28.                 {
  29.  
  30.                     userHolder[user] = new Dictionary<string, int>();
  31.                 }
  32.                 if (!userHolder[user].ContainsKey(ipS))
  33.                 {
  34.                     userHolder[user][ipS] = 0;
  35.                 }
  36.                 userHolder[user][ipS] += 1;
  37.             }
  38.  
  39.             foreach (var pair in userHolder)
  40.             {
  41.                 Console.WriteLine($"{pair.Key}:");
  42.  
  43.  
  44.                 var lenght  = pair.Value.Count;
  45.                 var counter = 0;
  46.  
  47.                 foreach (var pairS in pair.Value)
  48.                 {
  49.                     ++counter;
  50.  
  51.                     Console.Write($"{pairS.Key} => {pairS.Value}");
  52.  
  53.                     if (counter != lenght)
  54.                     {
  55.                         Console.Write(", ");
  56.                     }
  57.                     else
  58.                     {
  59.                         Console.Write(".");
  60.                     }
  61.  
  62.                 }
  63.                 Console.WriteLine();
  64.             }
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement