Advertisement
bacco

Logs Aggregator

Jun 12th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.43 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace test2
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.             var nameIpsDurations = new SortedDictionary
  12.                                  <string, SortedDictionary<string, int>>();
  13.  
  14.             var count = int.Parse(Console.ReadLine());
  15.  
  16.             for (int i = 0; i < count; i++)
  17.             {
  18.                 var input = Console.ReadLine();
  19.  
  20.                 var split = input.Split();
  21.  
  22.                 var user = split[1];
  23.                 var ipS  = split[0];
  24.                 var seconds = int.Parse(split[2]);
  25.  
  26.  
  27.                 if ( ! nameIpsDurations.ContainsKey(user))
  28.                 {
  29.                     nameIpsDurations[user] = new SortedDictionary<string, int>();
  30.                 }
  31.                 if ( ! nameIpsDurations[user].ContainsKey(ipS))
  32.                 {
  33.                     nameIpsDurations[user][ipS] = 0;
  34.                 }
  35.                 nameIpsDurations[user][ipS] += seconds;
  36.             }
  37.  
  38.  
  39.             foreach (var nameIpsDuration in nameIpsDurations)
  40.             {
  41.                 var name = nameIpsDuration.Key;
  42.                 var ipAdreses = nameIpsDuration.Value.Keys;
  43.                 var secondsSum = nameIpsDuration.Value.Values.Sum();
  44.  
  45.                 Console.WriteLine($"{name}: {secondsSum} [{string.Join(", ", ipAdreses)}]");
  46.             }
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement