Advertisement
Guest User

User Logs

a guest
Jun 24th, 2018
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.19 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace usersLogs
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string[] input = Console.ReadLine().Split().ToArray();
  12.  
  13.             string ip = input[0];
  14.             if (ip == "end")
  15.             {
  16.                 return;
  17.             }
  18.             string user = input[2];
  19.  
  20.             List<string> allIp = new List<string>();
  21.             List<string> allUsers = new List<string>();
  22.             //                             username,           IP's,   countIP;
  23.             var serverLogs = new Dictionary<string, Dictionary<string, int>>();
  24.  
  25.             while (true)
  26.             {
  27.                 allIp.Add(ip.Substring(3));
  28.                 allUsers.Add(user.Substring(5));
  29.                 input = Console.ReadLine().Split().ToArray();
  30.                 ip = input[0];
  31.  
  32.                 if (ip == "end")
  33.                 {
  34.                     break;
  35.                 }
  36.  
  37.                 user = input[2];
  38.             }
  39.  
  40.  
  41.             var ipResult = new Dictionary<string, int>();
  42.             int countSameIp = 1;
  43.  
  44.             for (int i = 0; i < allIp.Count; i++)
  45.             {
  46.                 for (int j = i + 1; j < allIp.Count; j++)
  47.                 {
  48.                     if (allIp[i] == allIp[j])
  49.                     {
  50.                         countSameIp++;
  51.                     }
  52.                 }
  53.  
  54.                 if (!ipResult.ContainsKey(allIp[i]))
  55.                 {
  56.                     ipResult[allIp[i]] = countSameIp;
  57.                 }
  58.  
  59.                 if (!serverLogs.ContainsKey(allUsers[i]))
  60.                 {
  61.                     serverLogs[allUsers[i]] = ipResult;
  62.                 }
  63.  
  64.  
  65.                 countSameIp = 1;
  66.             }
  67.  
  68.             foreach (var userLog in serverLogs)
  69.             {
  70.                 Console.Write($"{userLog.Key}:");
  71.                 Console.WriteLine();
  72.                 for (int i = 0; i < userLog.Value.Keys.Count; i++)
  73.                 {
  74.                     Console.WriteLine($"{string.Join(" ", userLog.Value.Keys)} => {string.Join(" ", userLog.Value.Values)}");
  75.                 }
  76.  
  77.             }
  78.         }
  79.     }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement