Advertisement
Vladimir76

User Logs

Feb 4th, 2017
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace User_Logs
  8. {
  9.     class Program
  10.     {
  11.         static void Main()
  12.         {
  13.             SortedDictionary<string, List<string>> sd = new SortedDictionary<string, List<string>>();
  14.             string input = null;
  15.             do
  16.             {
  17.                 input = Console.ReadLine();
  18.  
  19.                 if (input=="end")
  20.                 {
  21.                     break;
  22.                 }
  23.  
  24.                 List<string> inputList = input.Trim().Split(new char[] {'='},StringSplitOptions.RemoveEmptyEntries).ToList();
  25.                 List<string> inputList2 = inputList[1].Split(' ').ToList();
  26.                 string valueUser = inputList[inputList.Count - 1];
  27.                 string valueIP = inputList2[0];
  28.  
  29.                 if (sd.ContainsKey(valueUser))
  30.                 {
  31.                     sd[valueUser].Add(valueIP);
  32.                 }
  33.                 else
  34.                 {
  35.                     sd.Add(valueUser, new List<string>() { valueIP });
  36.                 }
  37.  
  38.             } while (input!="end");
  39.  
  40.             Dictionary<string, int> ipCounter = new Dictionary<string, int>();
  41.             int count = 1;
  42.  
  43.             foreach (KeyValuePair<string,List<string>> kvp in sd)
  44.             {
  45.                 for (int i = 0; i < kvp.Value.Count-1; i++)
  46.                 {
  47.                     for (int j = i+1; j < kvp.Value.Count; j++)
  48.                     {
  49.                         if (kvp.Value[i].Equals(kvp.Value[j]))
  50.                         {
  51.                             count++;
  52.                         }
  53.                         if (i==kvp.Value.Count-2 && j==kvp.Value.Count-1 && !ipCounter.ContainsKey(kvp.Value[j]))
  54.                         {
  55.                             ipCounter.Add(kvp.Value[j], count);
  56.                         }
  57.                     }
  58.                     if (ipCounter.ContainsKey(kvp.Value[i]))
  59.                     {
  60.                         count = 1;
  61.                     }
  62.                     else
  63.                     {
  64.                         ipCounter.Add(kvp.Value[i], count);
  65.                         count = 1;
  66.                     }
  67.                 }
  68.                 if (kvp.Value.Count == 1)
  69.                 {
  70.                     ipCounter.Add(kvp.Value[0], 1);
  71.                 }
  72.                 Console.WriteLine("{0}:",kvp.Key);
  73.                 Console.Write(string.Join(", ", ipCounter.Select(x => string.Format("{0} => {1}", x.Key, x.Value))));
  74.                 Console.WriteLine(".");
  75.                 ipCounter.Clear();
  76.             }
  77.         }
  78.  
  79.        
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement