Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class Program
- {
- static void Main()
- {
- Dictionary<string,Dictionary<string,int>> allusers=new Dictionary<string, Dictionary<string, int>>();
- string input;
- while ((input=Console.ReadLine())!="end")
- {
- Users(input,allusers);
- }
- PrintResult(allusers);
- }
- public static void Users(string input, Dictionary<string, Dictionary<string, int>> allusers)
- {
- string[] tokens = input.Split(new[] { ' ', '=' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
- string ip = tokens[1];
- string user = tokens[5];
- if (!allusers.ContainsKey(user))
- {
- allusers.Add(user, new Dictionary<string, int>());
- allusers[user].Add(ip, 1);
- }
- else
- {
- if (!allusers[user].ContainsKey(ip))
- {
- allusers[user].Add(ip, 1);
- }
- else
- {
- allusers[user][ip] += 1;
- }
- }
- }
- public static void PrintResult(Dictionary<string, Dictionary<string, int>> allusers)
- {
- var result = allusers.OrderBy(x => x.Key);
- foreach (var user in result)
- {
- Console.WriteLine($"{user.Key}:");
- int count = user.Value.Count;
- foreach (var details in user.Value)
- {
- count--;
- if (count == 0)
- {
- Console.WriteLine($"{details.Key} => {details.Value}.");
- }
- Console.WriteLine($"{details.Key} => {details.Value},");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment