Advertisement
Guest User

Untitled

a guest
May 30th, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.83 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 Logs_Aggregator
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int lines = int.Parse(Console.ReadLine());
  14.             List<string[]> data = new List<string[]>();
  15.             for (int i = 0; i < lines; i++)
  16.             {
  17.                 string[] input = Console.ReadLine().Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);
  18.                 data.Add(input);
  19.             }
  20.             SortedDictionary<string,string> output=new SortedDictionary<string, string>();
  21.             List<string> usedNames=new List<string>();
  22.             for (int i = 0; i < data.Count; i++)
  23.             {
  24.                 if (!usedNames.Contains(data[i][1]))
  25.                 {
  26.                     string name = data[i][1];
  27.                     usedNames.Add(name);
  28.                     SortedSet<string> ips = new SortedSet<string> ();
  29.                     int time = 0;
  30.                     for (int j = 0; j < data.Count; j++)
  31.                     {
  32.                         if (data[j][1] == name)
  33.                         {
  34.                             if (!ips.Contains(data[j][0]))
  35.                             {
  36.                                 ips.Add(data[j][0]);
  37.                             }
  38.                             time += int.Parse(data[j][2]);
  39.                         }
  40.                     }
  41.                     StringBuilder sb = new StringBuilder();
  42.                     sb.Append(time + " [" + string.Join(", ", ips) + "]");
  43.                     output.Add(name+": ",sb.ToString());
  44.                 }
  45.             }
  46.             foreach (var val in output)
  47.             {
  48.                 Console.WriteLine(val.Key+val.Value);
  49.             }
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement