distributed-computing/tasks/nikiforova-ts/Lab_2/worker-2/Program.cs

34 lines
1.1 KiB
C#
Raw Normal View History

 using System;
using System.IO;
using System.Text;
string[] numbers;
2023-12-02 10:45:25 +04:00
using (FileStream fstream = File.OpenRead("/var/result/data.txt"))
{
byte[] buffer = new byte[fstream.Length];
await fstream.ReadAsync(buffer, 0, buffer.Length);
string text = Encoding.Default.GetString(buffer);
text = text.Replace("\r\n", ";");
numbers = text.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
}
int maxNumber = int.MinValue;
foreach (var number in numbers)
{
int currentNumber = Convert.ToInt32(number);
if (currentNumber > maxNumber)
{
maxNumber = currentNumber;
}
}
int maxNumberSquared = maxNumber * maxNumber;
2023-12-02 10:45:25 +04:00
using (FileStream fstream = new FileStream("/var/result/result.txt", FileMode.OpenOrCreate))
{
byte[] buffer = Encoding.Default.GetBytes(maxNumberSquared.ToString());
await fstream.WriteAsync(buffer, 0, buffer.Length);
}
Console.WriteLine("Максимальное число во входных данных: " + maxNumber);
Console.WriteLine("Квадрат максимального числа: " + maxNumberSquared);