distributed-computing/tasks/yudenicheva-ds/lab_2/worker-2/Program.cs

34 lines
971 B
C#
Raw Permalink Normal View History

2023-12-19 03:38:18 +04:00
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 maxNum = int.MinValue;
foreach(var number in numbers)
{
int currentNum = Convert.ToInt32(number);
if(currentNum > maxNum)
{
maxNum = currentNum;
}
}
int maxNumSqr = maxNum * maxNum;
using (FileStream fstream = new FileStream("/var/result/result.txt", FileMode.OpenOrCreate))
{
byte[] buffer = Encoding.Default.GetBytes(maxNumSqr.ToString());
await fstream.WriteAsync(buffer, 0, buffer.Length);
}
Console.WriteLine("Максимальное число: " + maxNum);
Console.WriteLine("Возведение в квадрат: " + maxNumSqr);