distributed-computing/tasks/khalitova-am/lab_2/worker-2/Program.cs

30 lines
1001 B
C#
Raw Normal View History

2023-10-03 23:36:51 +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[]{';'});
}
int maxNumber = 0;
int maxNumberCount = 0;
foreach(var number in numbers){
if(Convert.ToInt32(number) < maxNumber){
continue;
}
if(Convert.ToInt32(number) == maxNumber){
maxNumberCount++;
continue;
}
if(Convert.ToInt32(number) > maxNumber){
maxNumber = Convert.ToInt32(number);
maxNumberCount = 1;
}
}
using(FileStream fstream = new FileStream("../../../../var/result/result.txt", FileMode.OpenOrCreate)){
byte[] buffer = Encoding.Default.GetBytes(maxNumberCount.ToString());
await fstream.WriteAsync(buffer, 0, buffer.Length);
}
Console.WriteLine(maxNumberCount);