Advertisement
j0nze

users log

May 1st, 2018
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.78 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 _06.User_Logs
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             SortedDictionary<string, int> userLogs = new SortedDictionary<string, int>();
  14.             List<string> userInformation = new List<string>();
  15.             List<string> userName = new List<string>();
  16.             string user = "";
  17.             string ipUserName = "";
  18.  
  19.             while (true)
  20.             {
  21.                 string input = Console.ReadLine();
  22.                 if (input == "end")
  23.                     break;
  24.  
  25.                 int startIndexIp = 3;
  26.                 int endIndexIp = input.IndexOf('m') - 1;
  27.                
  28.                 for (int i = input.LastIndexOf('=') + 1; i < input.Length; i++)
  29.                 {
  30.                     ipUserName += input[i];
  31.                     user += input[i];
  32.                 }
  33.                 ipUserName += " ";
  34.                 for (int i = startIndexIp; i < endIndexIp; i++)
  35.                 {
  36.                     ipUserName += input[i];
  37.                 }
  38.                 userName.Add(user);
  39.                 user = "";
  40.  
  41.                 if (userLogs.ContainsKey(ipUserName))
  42.                     userLogs[ipUserName]++;
  43.                 else
  44.                     userLogs[ipUserName] = 1;
  45.  
  46.                 ipUserName = "";
  47.             }
  48.             userName = userName.Distinct().ToList();
  49.             userName.Sort();
  50.  
  51.             int counter = 0;
  52.             int checker = 0;
  53.             for (int i = 0; i < userName.Count; i++)
  54.             {
  55.                 Console.WriteLine($"{userName[i]}: ");
  56.  
  57.                 for (int j = 0; j < userLogs.Count; j++)
  58.                 {
  59.                     if (userLogs.ElementAt(j).Key.Contains(userName[i]))
  60.                     {
  61.                         counter++;
  62.                     }
  63.                 }
  64.                 for (int y = 0; y < userLogs.Count; y++)
  65.                 {
  66.                     userInformation = userLogs.ElementAt(y).Key.Split(' ').ToList();
  67.                     if (userLogs.ElementAt(y).Key.Contains(userName[i]) && checker == counter - 1)
  68.                     {
  69.                         Console.Write($"{userInformation[1]} => {userLogs.ElementAt(y).Value}.");
  70.                         break;
  71.                     }
  72.                     if (userLogs.ElementAt(y).Key.Contains(userName[i]))
  73.                     {
  74.                         checker++;
  75.                         Console.Write($"{userInformation[1]} => {userLogs.ElementAt(y).Value}, ");
  76.                     }
  77.                 }
  78.                 Console.WriteLine();
  79.                 counter = 0;
  80.                 checker = 0;
  81.             }          
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement