using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace TMI_practicum { internal class Program { public static void Main(string[] args) { if (args.Length < 1) { Console.WriteLine("Please enter a file."); Environment.Exit(1); } if (!File.Exists(args[0])) { Console.WriteLine("File {0} not found.", args[0]); Environment.Exit(1); } } private static Tuple> ParseFile(string path) { byte algoritm = 0; int nbCircles = 0; var circles = new List(); using (StreamReader file = new StreamReader(path)) { try { algoritm = byte.Parse(file.ReadLine()); nbCircles = int.Parse(file.ReadLine()); string line; while ((line = file.ReadLine()) != null) { 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>(algoritm, nbCircles, circles); } private static readonly string OutputFile = "output.txt"; private static void WriteOutput(IEnumerable 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; } } } }