distributed-computing/tasks/andrianov-ep/lab_2/worker-2/Program.cs
2024-01-08 20:55:20 +04:00

24 lines
781 B
C#

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[]{';'});
}
int maxNumber = 0;
int n = 0;
foreach(var number in numbers){
if(Convert.ToInt32(number) > maxNumber){
maxNumber = Convert.ToInt32(number);
n = maxNumber*maxNumber;
}
}
using(FileStream fstream = new FileStream("/var/result/result.txt", FileMode.OpenOrCreate)){
byte[] buffer = Encoding.Default.GetBytes(n.ToString());
await fstream.WriteAsync(buffer, 0, buffer.Length);
}
Console.WriteLine(n);