distributed-computing/tasks/kazakov-ev/lab_2/worker-2/Program.cs
2023-10-17 10:12:55 +03:00

24 lines
803 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);