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 _06.User_Logs
- {
- class Program
- {
- static void Main(string[] args)
- {
- SortedDictionary<string, int> userLogs = new SortedDictionary<string, int>();
- List<string> userInformation = new List<string>();
- List<string> userName = new List<string>();
- string user = "";
- string ipUserName = "";
- while (true)
- {
- string input = Console.ReadLine();
- if (input == "end")
- break;
- int startIndexIp = 3;
- int endIndexIp = input.IndexOf('m') - 1;
- for (int i = input.LastIndexOf('=') + 1; i < input.Length; i++)
- {
- ipUserName += input[i];
- user += input[i];
- }
- ipUserName += " ";
- for (int i = startIndexIp; i < endIndexIp; i++)
- {
- ipUserName += input[i];
- }
- userName.Add(user);
- user = "";
- if (userLogs.ContainsKey(ipUserName))
- userLogs[ipUserName]++;
- else
- userLogs[ipUserName] = 1;
- ipUserName = "";
- }
- userName = userName.Distinct().ToList();
- userName.Sort();
- int counter = 0;
- int checker = 0;
- for (int i = 0; i < userName.Count; i++)
- {
- Console.WriteLine($"{userName[i]}: ");
- for (int j = 0; j < userLogs.Count; j++)
- {
- if (userLogs.ElementAt(j).Key.Contains(userName[i]))
- {
- counter++;
- }
- }
- for (int y = 0; y < userLogs.Count; y++)
- {
- userInformation = userLogs.ElementAt(y).Key.Split(' ').ToList();
- if (userLogs.ElementAt(y).Key.Contains(userName[i]) && checker == counter - 1)
- {
- Console.Write($"{userInformation[1]} => {userLogs.ElementAt(y).Value}.");
- break;
- }
- if (userLogs.ElementAt(y).Key.Contains(userName[i]))
- {
- checker++;
- Console.Write($"{userInformation[1]} => {userLogs.ElementAt(y).Value}, ");
- }
- }
- Console.WriteLine();
- counter = 0;
- checker = 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement