96 lines
2.5 KiB
C#
96 lines
2.5 KiB
C#
namespace omp
|
|
{
|
|
public class Configurator
|
|
{
|
|
public int xsize;
|
|
public int ysize;
|
|
public int zCoordinate;
|
|
public List<Point> stations = [];
|
|
|
|
public Configurator(string[] args)
|
|
{
|
|
List<string> lines;
|
|
|
|
if (args.Length == 0)
|
|
{
|
|
Console.WriteLine("Input parameters:");
|
|
|
|
lines = [];
|
|
|
|
string? line;
|
|
while ((line = Console.ReadLine()) != null && line != "")
|
|
{
|
|
lines.Add(line);
|
|
}
|
|
}
|
|
else if (args.Length == 1)
|
|
{
|
|
lines = new(File.ReadAllLines(args[0]));
|
|
}
|
|
else
|
|
{
|
|
throw new ArgumentException("You must either provide path to parameters file as an only cli argument, or insert it into STDIN");
|
|
}
|
|
|
|
ParseParameters(lines);
|
|
}
|
|
|
|
private void ParseParameters(IReadOnlyList<string> lines)
|
|
{
|
|
bool hasZ = CheckHasZ(lines[1]);
|
|
|
|
ParseSize(lines[0]);
|
|
ParseZCoord(lines[1], hasZ);
|
|
ParseStations(lines, hasZ);
|
|
}
|
|
|
|
private static bool CheckHasZ(string line)
|
|
{
|
|
return line.Split(' ').Length == 1; // line contains a single number, z coordinate
|
|
}
|
|
|
|
private void ParseSize(string line)
|
|
{
|
|
string[] size_parts = line.Split(' ', 2);
|
|
xsize = int.Parse(size_parts[0]);
|
|
ysize = int.Parse(size_parts[1]);
|
|
}
|
|
|
|
private void ParseZCoord(string line, bool hasZ)
|
|
{
|
|
if (hasZ)
|
|
{
|
|
zCoordinate = int.Parse(line);
|
|
}
|
|
else
|
|
{
|
|
zCoordinate = 0;
|
|
}
|
|
}
|
|
|
|
private void ParseStations(IReadOnlyList<string> lines, bool hasZ)
|
|
{
|
|
int firstIndex = 1 + (hasZ ? 1 : 0);
|
|
for (int i = firstIndex; i < lines.Count; ++i)
|
|
{
|
|
string[] point_parts = lines[i].Split(' ', 2 + (hasZ ? 1 : 0));
|
|
|
|
int x, y, z;
|
|
|
|
x = int.Parse(point_parts[0]) - 1;
|
|
y = int.Parse(point_parts[1]) - 1;
|
|
|
|
if (hasZ)
|
|
{
|
|
z = int.Parse(point_parts[2]);
|
|
}
|
|
else
|
|
{
|
|
z = 0;
|
|
}
|
|
|
|
stations.Add(new Point(x, y, z));
|
|
}
|
|
}
|
|
}
|
|
} |