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.Threading.Tasks;
- namespace User_Logs
- {
- class Program
- {
- static void Main()
- {
- SortedDictionary<string, List<string>> sd = new SortedDictionary<string, List<string>>();
- string input = null;
- do
- {
- input = Console.ReadLine();
- if (input=="end")
- {
- break;
- }
- List<string> inputList = input.Trim().Split(new char[] {'='},StringSplitOptions.RemoveEmptyEntries).ToList();
- List<string> inputList2 = inputList[1].Split(' ').ToList();
- string valueUser = inputList[inputList.Count - 1];
- string valueIP = inputList2[0];
- if (sd.ContainsKey(valueUser))
- {
- sd[valueUser].Add(valueIP);
- }
- else
- {
- sd.Add(valueUser, new List<string>() { valueIP });
- }
- } while (input!="end");
- Dictionary<string, int> ipCounter = new Dictionary<string, int>();
- int count = 1;
- foreach (KeyValuePair<string,List<string>> kvp in sd)
- {
- for (int i = 0; i < kvp.Value.Count-1; i++)
- {
- for (int j = i+1; j < kvp.Value.Count; j++)
- {
- if (kvp.Value[i].Equals(kvp.Value[j]))
- {
- count++;
- }
- if (i==kvp.Value.Count-2 && j==kvp.Value.Count-1 && !ipCounter.ContainsKey(kvp.Value[j]))
- {
- ipCounter.Add(kvp.Value[j], count);
- }
- }
- if (ipCounter.ContainsKey(kvp.Value[i]))
- {
- count = 1;
- }
- else
- {
- ipCounter.Add(kvp.Value[i], count);
- count = 1;
- }
- }
- if (kvp.Value.Count == 1)
- {
- ipCounter.Add(kvp.Value[0], 1);
- }
- Console.WriteLine("{0}:",kvp.Key);
- Console.Write(string.Join(", ", ipCounter.Select(x => string.Format("{0} => {1}", x.Key, x.Value))));
- Console.WriteLine(".");
- ipCounter.Clear();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement