Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- namespace ConsoleApplication1
- {
- class TimesheetRow
- {
- public int Hour { get; set; }
- public int Minute { get; set; }
- public int Second { get; set; }
- public int Distance { get; set; }
- public string Origin { get; set; }
- }
- class Program
- {
- private static IEnumerable<TimesheetRow> ParseFile(string path)
- {
- using (var reader = new StreamReader(path))
- {
- string line;
- while ((line = reader.ReadLine()) != null)
- {
- var parts = line.Split(' ');
- yield return
- new TimesheetRow
- {
- Hour = int.Parse(parts[0]),
- Minute = int.Parse(parts[1]),
- Second = int.Parse(parts[2]),
- Distance = int.Parse(parts[3]),
- Origin = parts[4]
- };
- }
- }
- }
- private static void Main(string[] args)
- {
- var list = ParseFile(args[0]).ToList();
- Console.WriteLine("Parsed {0} rows.", list.Count);
- var top5 = list.OrderByDescending(r => r.Distance).Take(5).ToList();
- Console.WriteLine("Top {0} rows by distance:", top5.Count);
- top5.ForEach(
- row => Console.WriteLine("{0:D2}:{1:D2}:{2:D2} {3} - {4}",
- row.Hour, row.Minute, row.Second,
- row.Origin, row.Distance));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement