Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Text.RegularExpressions;
- class UserLogs
- {
- static void Main()
- {
- string inputLine = Console.ReadLine();
- StringBuilder iPLogs = new StringBuilder();
- SortedDictionary<string, Dictionary<string, int>> output = new SortedDictionary<string, Dictionary<string, int>>();
- while (inputLine != "end")
- {
- iPLogs.Append(inputLine);
- iPLogs.Append("\n\r");
- inputLine = Console.ReadLine();
- }
- Regex regex = new Regex(@"IP=(.+) message=.+ user=(.+)");
- MatchCollection matches = regex.Matches(iPLogs.ToString());
- foreach (Match match in matches)
- {
- Dictionary<string, int> subDictionary = new Dictionary<string, int>();
- string iP = match.Groups[1].ToString();
- string user = match.Groups[2].ToString();
- if (output.ContainsKey(user))
- {
- subDictionary = output[user];
- if (subDictionary.ContainsKey(iP))
- {
- int repetitions = subDictionary[iP] + 1;
- subDictionary[iP] = repetitions;
- }
- else
- {
- subDictionary.Add(iP, 1);
- }
- output[user] = subDictionary;
- }
- else
- {
- subDictionary.Add(iP, 1);
- output.Add(user, subDictionary);
- }
- }
- foreach (var subDictionary in output)
- {
- Console.WriteLine("{0}: ", subDictionary.Key);
- int counter = 1;
- foreach (var ip in subDictionary.Value)
- {
- Console.Write("{0} => {1}", ip.Key, ip.Value);
- if (counter == subDictionary.Value.Count)
- {
- Console.WriteLine(".");
- }
- else
- {
- Console.Write(", ");
- }
- counter++;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement