Advertisement
Guest User

Untitled

a guest
Feb 7th, 2017
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace UserLogs
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             var dictionary = new SortedDictionary<string, Dictionary<string, int>>();
  14.             var address = new Dictionary<string, int>();
  15.             var input = Console.ReadLine();
  16.  
  17.             while (input != "end")
  18.             {
  19.                 var items = input.Split(' ', '=').ToArray();
  20.                 var username = items.Last();
  21.                 var ip = items[1];
  22.                 var count = 1;
  23.                 if (!dictionary.ContainsKey(username))
  24.                 {
  25.                     address = new Dictionary<string, int>();
  26.                     address[ip] = count;
  27.                     dictionary[username] = address;
  28.                 }
  29.                 else if (dictionary.ContainsKey(username))
  30.                 {
  31.                     if (!address.ContainsKey(ip))
  32.                     {
  33.                         address[ip] = count;
  34.                     }
  35.                     else if (address.ContainsKey(ip))
  36.                     {
  37.                         var currentValue = 0;
  38.                         address.TryGetValue(ip, out currentValue);
  39.                         address[ip] = count + currentValue;
  40.                     }
  41.                 }
  42.                 input = Console.ReadLine();
  43.             }
  44.             foreach (var users in dictionary)
  45.             {
  46.                 Console.WriteLine($"{users.Key}: ");
  47.                 foreach (var addresses in users.Value)
  48.                 {
  49.                     if (addresses.Equals(users.Value.Last()))
  50.                     {
  51.                         Console.WriteLine($"{addresses.Key} => {addresses.Value}.");
  52.                         break;
  53.                     }
  54.                     Console.Write($"{addresses.Key} => {addresses.Value}, ");
  55.                 }
  56.             }
  57.         }
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement