DAS_2024_1/kuzarin_maxim_lab_2/SecondApplication/Program.cs

31 lines
972 B
C#
Raw Permalink Normal View History

Console.WriteLine("Запущен второй сервис");
string inputPath = Environment.GetEnvironmentVariable("INPUT_PATH") ?? ".\\input2";
string outputPath = Environment.GetEnvironmentVariable("OUTPUT_PATH") ?? ".\\output2";
if (!Directory.Exists(outputPath))
Directory.CreateDirectory(outputPath);
var inputFilePath = Path.Combine(inputPath, "data.txt");
var outputFilePath = Path.Combine(outputPath, "result.txt");
if (!File.Exists(inputFilePath))
{
Console.WriteLine($"Нет исходного файла {inputFilePath}");
return;
}
using var reader = new StreamReader(inputFilePath);
long maxNumber = 0;
while (true)
{
var str = reader.ReadLine();
if (str == null) break;
if (long.TryParse(str, out var number) && number > maxNumber)
maxNumber = number;
}
File.WriteAllText(outputFilePath, (maxNumber * maxNumber).ToString());
Console.WriteLine($"Результат выполнения: {maxNumber * maxNumber}");