plamen83

Untitled

Jun 18th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 KB | None | 0 0
  1. namespace _06.User_Logs
  2. {
  3.  
  4.     using System;
  5.     using System.Collections.Generic;
  6.     using System.Linq;
  7.  
  8.  
  9.     public class Dictionaries
  10.     {
  11.  
  12.         public static void Main()
  13.         {
  14.             var input = Console.ReadLine().Split(' ', '=').ToArray();
  15.  
  16.             var userAndIP = new SortedDictionary<string, SortedDictionary<string, int>>();
  17.             while (input[0] != "end")
  18.             {
  19.                 var user = input[input.Length - 1];
  20.  
  21.                 if (!userAndIP.Keys.Contains(user))
  22.                 {
  23.                     userAndIP[user] = new SortedDictionary<string, int>();
  24.  
  25.                 }
  26.  
  27.                 userAndIP[user] = CountIPentries(userAndIP[user], input);
  28.  
  29.                 input = Console.ReadLine().Split(' ', '=').ToArray();
  30.             }
  31.  
  32.             foreach (var user in userAndIP)
  33.             {
  34.                 Console.WriteLine("{0}:", user.Key);
  35.  
  36.                 Console.WriteLine(string.Join(", ", user.Value.Select(x => $"{x.Key} => {x.Value}")) + ".");
  37.             }
  38.  
  39.  
  40.  
  41.         }
  42.  
  43.         public static SortedDictionary<string, int> CountIPentries
  44.             (SortedDictionary<string, int> dict, string[] input)
  45.         {
  46.             var IP = input[1];
  47.  
  48.             if (!dict.Keys.Contains(IP))
  49.             {
  50.                 dict[IP] = 0;
  51.             }
  52.  
  53.             dict[IP]++;
  54.  
  55.             return dict;
  56.         }
  57.     }
  58. }
Add Comment
Please, Sign In to add comment