Advertisement
gardax

AverageLoadTime

Apr 9th, 2014
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5.  
  6. namespace _13_AverageLoadTimeCalculator
  7. {
  8.     class AverageLoadTimeCalculator
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string line = Console.ReadLine();
  13.             Dictionary<string, double> sumOfTime = new Dictionary<string, double> ();
  14.             Dictionary<string, int> countOfLoads=new Dictionary<string, int>();
  15.  
  16.             while (line != string.Empty)
  17.             {
  18.                 string[] list = line.Split(' ');
  19.                 string link = list[2];
  20.                 double loadTime = double.Parse(list[3], CultureInfo.InvariantCulture);
  21.                 if (!sumOfTime.Keys.Contains(link))
  22.                 {
  23.                     sumOfTime[link] = loadTime;
  24.                     countOfLoads[link] = 1;
  25.                 }
  26.                 else
  27.                 {
  28.                     sumOfTime[link] = sumOfTime[link] + loadTime;
  29.                     countOfLoads[link]++;
  30.                 }
  31.                 line = Console.ReadLine();
  32.             }
  33.  
  34.             foreach (string link in sumOfTime.Keys)
  35.             {
  36.                 Console.WriteLine(link + " --> " + sumOfTime[link]/countOfLoads[link]);
  37.             }
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement