1
0

Finished parsing

This commit is contained in:
2019-05-09 12:50:05 +02:00
parent 865c08f157
commit 610a2372eb
3 changed files with 68 additions and 23 deletions

View File

@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace TMI_practicum
{
@@ -18,29 +20,83 @@ namespace TMI_practicum
Console.WriteLine("File {0} not found.", args[0]);
Environment.Exit(1);
}
Console.WriteLine("HOOOOOOOOOOOIIII");
}
private static void ParseFile(string path)
private static Tuple<byte, int, ICollection<Circle>> ParseFile(string path)
{
int algoritme = 0;
byte algoritm = 0;
int nbCircles = 0;
var circles = new List<Circle>();
using (StreamReader file = new StreamReader(path))
{
if (!int.TryParse(file.ReadLine(), out algoritme) || !int.TryParse(file.ReadLine(), out nbCircles))
try
{
throw new ArgumentException("An error occured parsing the input file.");
}
algoritm = byte.Parse(file.ReadLine());
nbCircles = int.Parse(file.ReadLine());
string line;
while ((line = file.ReadLine()) != null)
{
line.Split(' ');
}
double[] parts = line.Split(' ').Select(double.Parse).ToArray();
circles.Add(new Circle(parts[0], parts[1], parts[2]));
}
}
catch (Exception)
{
Console.WriteLine("An error occured parsing the input file.\r\n" +
"Make sure the file has all required values and consists only of numbers.");
Environment.Exit(1);
}
}
return new Tuple<byte, int, ICollection<Circle>>(algoritm, nbCircles, circles);
}
private static readonly string OutputFile = "output.txt";
private static void WriteOutput(IEnumerable<Intersection> intersections, double time)
{
if (File.Exists(OutputFile))
{
File.Delete(OutputFile);
}
using (StreamWriter sw = File.CreateText(OutputFile))
{
foreach (var intersection in intersections)
{
sw.WriteLine("{0}\t{1}", intersection.X, intersection.Y);
}
sw.WriteLine("\r\n{0}", time);
}
}
private struct Circle
{
public readonly double X;
public readonly double Y;
public readonly double R;
public Circle(double x, double y, double r)
{
X = x;
Y = y;
R = r;
}
}
private struct Intersection
{
public readonly double X;
public readonly double Y;
public Intersection(double x, double y)
{
X = x;
Y = y;
}
}
}

View File

@@ -37,19 +37,12 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51">
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

View File

@@ -1,4 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="System.ValueTuple" version="4.5.0" targetFramework="net462" />
</packages>