distributed-computing/tasks/kazakov-ev/lab_2/worker-2/Program.cs

24 lines
781 B
C#
Raw Normal View History

2023-10-17 11:12:23 +04:00
using System.Text;
2023-10-17 11:12:55 +04:00
string[] numbers;
2023-10-17 11:25:32 +04:00
using (FileStream fstream = File.OpenRead("/var/result/data.txt")){
2023-10-17 11:12:55 +04:00
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[]{';'});
}
2023-10-17 11:12:23 +04:00
int maxNumber = 0;
2023-10-17 11:12:55 +04:00
int n = 0;
2023-10-17 11:12:23 +04:00
foreach(var number in numbers){
2023-10-17 11:12:55 +04:00
if(Convert.ToInt32(number) > maxNumber){
maxNumber = Convert.ToInt32(number);
n = maxNumber*maxNumber;
2023-10-17 11:12:23 +04:00
}
}
2023-10-17 11:25:32 +04:00
using(FileStream fstream = new FileStream("/var/result/result.txt", FileMode.OpenOrCreate)){
2023-10-17 11:12:55 +04:00
byte[] buffer = Encoding.Default.GetBytes(n.ToString());
2023-10-17 11:12:23 +04:00
await fstream.WriteAsync(buffer, 0, buffer.Length);
}
2023-10-17 11:12:55 +04:00
Console.WriteLine(n);