Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // We have a report that holds dates, web site URLs and load times (in seconds) in the same format like in the examples below. Your tasks is to calculate the average load time for each URL. Print the URLs in the same order as they first appear in the input report. Use double floating-point precision.
- namespace _13.AverageLoadTimeCalculator
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- public class AverageLoadTimeCalculator
- {
- public static void Main(string[] args)
- {
- checked
- {
- Console.WriteLine("Enter your Web sites load times Report:");
- string reportStr = Console.ReadLine();
- Dictionary<string, List<double>> websitesTimes = new Dictionary<string, List<double>>();
- while (reportStr != string.Empty)
- {
- char[] separators = new char[] { ' ', ',', ';' };
- string[] reportArr = reportStr.Split(separators, StringSplitOptions.RemoveEmptyEntries);
- for (int i = 2; i < reportArr.Length; i++)
- {
- if (i == 2)
- {
- string key = reportArr[i];
- double time = double.Parse(reportArr[i + 1]);
- if (!websitesTimes.Keys.Contains(key))
- {
- websitesTimes.Add(key, new List<double>());
- }
- websitesTimes[key].Add(time);
- }
- }
- reportStr = Console.ReadLine();
- }
- Console.WriteLine("The Average Load Time for each Web Site in that report is:");
- foreach (var url in websitesTimes)
- {
- Console.WriteLine("{0} -> {1}", url.Key, url.Value.Average());
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement