-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
50 lines (41 loc) · 1.49 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace HallOfFameSorter
{
class Program
{
static void Main(string[] args)
{
const string inputFile = "HallOfFame.txt";
string input;
using (var reader = new FileInfo(inputFile).OpenText())
{
input = reader.ReadToEnd();
}
var lines = input.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
var data = lines.Select(line => new LineWithDate
{
Line = line,
Date = DateTime.Parse(line.Split(new[] {" "}, StringSplitOptions.RemoveEmptyEntries)[0])
}).ToList();
var output = new StringBuilder();
foreach (var datum in data.OrderByDescending(i => i.Date))
{
output.AppendLine(datum.Line);
}
var parts = inputFile.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
using (var writer = new FileInfo(parts[0] + "_formatted." + parts[1]).CreateText())
{
writer.Write(output.ToString().Trim());
}
}
}
class LineWithDate
{
public string Line { get; set; }
public DateTime Date { get; set; }
}
}