This commit is contained in:
Eugene Kazakov 2023-10-17 10:12:23 +03:00
parent ae5a52f365
commit 7a6fa0a5e4
6 changed files with 76 additions and 4 deletions

View File

@ -0,0 +1,13 @@
version: "3.1"
services:
worker-1:
build: ./worker-1
volumes:
- ./data:/var/data
- ./result:/var/result
worker-2:
build: ./worker-2
volumes:
- ./result:/var/result
depends_on:
- worker-1

View File

@ -0,0 +1,3 @@
1
2
3

View File

@ -0,0 +1,5 @@
1
1
1
1
1

View File

@ -0,0 +1,10 @@
10
10
10
10
10
10
10
10
10
10

View File

@ -1,2 +1,22 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
using System.Text;
string[] files = Directory.GetFiles("/var/data");
string maxFilePath = "";
long maxL = 0;
foreach(var filePath in files){
FileInfo fileInfo = new FileInfo(filePath);
if(fileInfo.Length > maxL){
maxL = fileInfo.Length;
maxFilePath = filePath;
}
}
using (FileStream fstream = File.OpenRead(maxFilePath)){
byte[] buffer = new byte[fstream.Length];
await fstream.ReadAsync(buffer, 0, buffer.Length);
string text = Encoding.Default.GetString(buffer);
using(FileStream fstream1 = new FileStream("/var/result/data.txt", FileMode.OpenOrCreate)){
fstream1.SetLength(0);
byte[] buffer1 = Encoding.Default.GetBytes(text);
await fstream1.WriteAsync(buffer1, 0, buffer1.Length);
}
}

View File

@ -1,2 +1,23 @@
// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");
using System.Text;
int[] numbers = File.ReadAllLines("../../../../var/data/data.txt").Select(x=> int.Parse(x)).ToArray();
int maxNumber = 0;
int maxNumberCount = 0;
foreach(var number in numbers){
if(number < maxNumber){
continue;
}
if(number == maxNumber){
maxNumberCount++;
continue;
}
if(number > maxNumber){
maxNumber = 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);