Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class UserLogs
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- var logs = new SortedDictionary<string, Dictionary<string, int>>();
- while (input != "end")
- {
- string[] inputArr = input
- .Split()
- .ToArray();
- string ip = inputArr.First().Remove(0, 3);
- string user = inputArr.Last().Remove(0, 5);
- if (logs.ContainsKey(user) == false)
- {
- logs.Add(user, new Dictionary<string, int>());
- }
- if (logs[user].ContainsKey(ip) == false)
- {
- logs[user].Add(ip, 0);
- }
- logs[user][ip]++;
- input = Console.ReadLine();
- }
- foreach (var user in logs)
- {
- Console.WriteLine($"{user.Key}:");
- string ips = "";
- foreach (var ip in user.Value)
- {
- ips += $"{ip.Key} => {ip.Value}, ";
- }
- ips = ips.Remove(ips.Length - 2) + ".";
- Console.WriteLine(ips);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment