distributed-computing/tasks/fomichev-ai/lab_2/worker-2/Program.cs

24 lines
718 B
C#
Raw Permalink Normal View History

2023-10-16 21:25:24 +04:00
var dir = new DirectoryInfo("/var/data");
2023-10-08 17:01:18 +04:00
var fileName = dir.GetFiles().First().Name;
string[] numbers = File.ReadAllLines("/var/data/" + fileName);
long k = 0;
long min = long.MaxValue;
foreach (var numberStr in numbers)
{
if (!int.TryParse(numberStr, out int number))
continue;
if (number < min)
min = number;
}
foreach (var numberStr in numbers)
{
if (!int.TryParse(numberStr, out int number))
continue;
if (min == number)
k++;
}
File.WriteAllText("/var/result/result.txt", k.ToString());
Console.WriteLine("Сервис 2 отработал успешно!");
Console.WriteLine($"Наименьшее число:= {min} , число вхождений:= {k}");