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 ConsoleApplication4
- {
- class Program
- {
- static void Main(string[] args)
- {
- var freights = new List<FreightModel>();
- if (File.Exists("tavok.txt"))
- {
- using (var sr = new StreamReader("tavok.txt"))
- {
- while (!sr.EndOfStream)
- {
- var line = sr.ReadLine();
- if (string.IsNullOrWhiteSpace(line))
- {
- throw new Exception("Empty line");
- }
- var parts = line.Split(' ');
- freights.Add(new FreightModel
- {
- Day = int.Parse(parts[0]),
- Freight = int.Parse(parts[1]),
- Distance = int.Parse(parts[2])
- });
- }
- }
- }
- freights = freights.GroupBy(g => g.Day).OrderBy(g => g.Key).SelectMany(g => g.OrderBy(x => x.Freight)).ToList();
- //foreach (var item in freights)
- //{
- // Console.WriteLine("{0} {1} {2}", item.Day, item.Freight, item.Distance);
- //}
- var first = freights.FirstOrDefault();
- if (first != null)
- {
- Console.WriteLine("First freight: {0} {1} {2}", first.Day, first.Freight, first.Distance);
- }
- var last = freights.LastOrDefault(x => x.Day == 7);
- if (last != null)
- {
- Console.WriteLine("Last freight at day 7: {0} {1} {2}", last.Day, last.Freight, last.Distance);
- }
- Console.ReadLine();
- }
- }
- class FreightModel
- {
- public int Day { get; set; }
- public int Freight { get; set; }
- public int Distance { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement