Advertisement
Guest User

Untitled

a guest
Oct 8th, 2016
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.23 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace AsyncronousProgramming
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string command = Console.ReadLine();
  12.             var input = new Dictionary<string, Dictionary<string, int>>();
  13.  
  14.             while (command != "end")
  15.             {
  16.                 var tokens = command
  17.                     .Split(new string[] { "IP=", " ", "user=" }, StringSplitOptions.RemoveEmptyEntries);
  18.                 var ip = tokens[0];
  19.                 var user = tokens[2];
  20.  
  21.                 if (!input.ContainsKey(user))
  22.                 {
  23.                     input.Add(user, new Dictionary<string, int>());
  24.                 }
  25.  
  26.                 if (!input[user].ContainsKey(ip))
  27.                 {
  28.                     input[user].Add(ip, 0);
  29.                 }
  30.  
  31.                 input[user][ip]++;
  32.                 command = Console.ReadLine();
  33.             }
  34.  
  35.             foreach (var item in input.OrderBy(x => x.Key))
  36.             {
  37.                 Console.WriteLine($"{item.Key}: ");
  38.                 Console.WriteLine($"{string.Join(", ", item.Value.Select(x=> $"{x.Key} => {x.Value}"))}.");
  39.             }
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement