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

34 lines
1.1 KiB
C#

using System;
using System.IO;
using System.Text;
string[] numbers;
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;
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);