Advertisement
VKNikov

Untitled

Apr 13th, 2014
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class LoadTimeCalculator
  6. {
  7.     static void Main()
  8.     {
  9.         Console.WriteLine("This program reads a report of web sites and load times. After that it calculates the average load time for each URL.");
  10.         Console.WriteLine("Please enter a report:");
  11.  
  12.         Dictionary<string, List<double>> dict = new Dictionary<string, List<double>>();
  13.         string input = Console.ReadLine();
  14.        
  15.         while (input != string.Empty)
  16.         {
  17.             input = input.Substring(18);
  18.             string [] splitted = input.Split(' ');
  19.  
  20.             if (!dict.Keys.Contains(splitted[0]))
  21.             {
  22.                 dict.Add(splitted[0], new List<double> { double.Parse(splitted[1]) });
  23.             }
  24.             else
  25.             {
  26.                 dict[splitted[0]].Add(double.Parse(splitted[1]));
  27.             }
  28.            
  29.             input = Console.ReadLine();
  30.         }
  31.  
  32.         Console.WriteLine("The average load time for each URL is:");
  33.  
  34.         foreach (var entry in dict)
  35.         {
  36.             Console.WriteLine("{0} -> {1}", entry.Key, entry.Value.Average());
  37.         }
  38.        
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement