Advertisement
Guest User

Egyszerubb.

a guest
Oct 16th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.62 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5.  
  6. namespace ConsoleApplication1
  7. {
  8.     class TimesheetRow
  9.     {
  10.         public int Hour { get; set; }
  11.         public int Minute { get; set; }
  12.         public int Second { get; set; }
  13.         public int Distance { get; set; }
  14.         public string Origin { get; set; }
  15.     }
  16.  
  17.     class Program
  18.     {
  19.         private static void Main(string[] args)
  20.         {
  21.             var list = new List<TimesheetRow>();
  22.  
  23.             using (var reader = new StreamReader(args[0]))
  24.             {
  25.                 string line;
  26.                 while ((line = reader.ReadLine()) != null)
  27.                 {
  28.                     var parts = line.Split(' ');
  29.                     var row = new TimesheetRow
  30.                         {
  31.                             Hour = int.Parse(parts[0]),
  32.                             Minute = int.Parse(parts[1]),
  33.                             Second = int.Parse(parts[2]),
  34.                             Distance = int.Parse(parts[3]),
  35.                             Origin = parts[4]
  36.                         };
  37.  
  38.                     list.Add(row);
  39.                 }
  40.             }    
  41.  
  42.             Console.WriteLine("Parsed {0} rows.", list.Count);
  43.  
  44.             var top5 = list.OrderByDescending(r => r.Distance).Take(5).ToList();
  45.  
  46.             Console.WriteLine("Top {0} rows by distance:", top5.Count);
  47.             top5.ForEach(
  48.                 row => Console.WriteLine("{0:D2}:{1:D2}:{2:D2} {3} - {4}",
  49.                     row.Hour, row.Minute, row.Second,
  50.                     row.Origin, row.Distance));
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement