Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace UserLogs
- {
- class Program
- {
- static void Main(string[] args)
- {
- var dict = new SortedDictionary<string, Dictionary<string, List<string>>>();
- string input = Console.ReadLine();
- Regex pattern = new Regex(@"(?:IP=|)(?<ip>\S+)\s+(?:message=')(?<message>|\S+)(?:')\s+(?:user=)(?<user>\S+)");
- while (input != "end")
- {
- Match match = pattern.Match(input);
- string message = match.Groups[2].Value;
- string user = match.Groups[3].Value;
- string ip = match.Groups[1].Value;
- if (dict.ContainsKey(user))
- {
- if (dict[user].ContainsKey(ip))
- {
- dict[user][ip].Add(message);
- }
- else
- {
- dict[user].Add(ip, new List<string>() {message} );
- }
- }
- else
- {
- dict.Add(user, new Dictionary<string, List<string>>());
- dict[user].Add(ip, new List<string> { message });
- }
- input = Console.ReadLine(); // new input
- }
- //Print dict
- foreach (var item in dict)
- {
- Console.WriteLine(item.Key + ":");
- Console.WriteLine(String.Join(", ", item.Value.Select(x => x.Key + " => " + x.Value.Count)) + ".");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement