64 lines
1.8 KiB
C#
64 lines
1.8 KiB
C#
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
|
|
namespace CommonConsole
|
|
{
|
|
public class Program
|
|
{
|
|
public static void Main()
|
|
{
|
|
var aggregatedValues = new Dictionary<double, double[]>();
|
|
|
|
foreach (var line in File.ReadAllLines("test.txt"))
|
|
{
|
|
if (string.IsNullOrWhiteSpace(line))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
var tokens = line.Split(new[] { '\t', ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
if (tokens.Length != 2)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (!double.TryParse(tokens[0], out var temperature) || !double.TryParse(tokens[1], out var timeOfFlight))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (temperature < 0 || temperature > 40 || timeOfFlight < 0 || timeOfFlight > 1)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
if (!aggregatedValues.ContainsKey(temperature))
|
|
{
|
|
aggregatedValues[temperature] = new [] { double.MaxValue, double.MinValue };
|
|
}
|
|
|
|
var values = aggregatedValues[temperature];
|
|
|
|
if (values[0] > timeOfFlight)
|
|
{
|
|
values[0] = timeOfFlight;
|
|
}
|
|
|
|
if (values[1] < timeOfFlight)
|
|
{
|
|
values[1] = timeOfFlight;
|
|
}
|
|
}
|
|
|
|
File.WriteAllText("test.json", JsonConvert.SerializeObject(aggregatedValues
|
|
.Select(x => new double[] { x.Key, x.Value[0], x.Value[1] })
|
|
.ToArray(), Formatting.Indented));
|
|
}
|
|
}
|
|
}
|
|
|