2023-10-10 16:40:13 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
2023-10-17 23:06:18 +04:00
|
|
|
|
string filePath = "/var/data/data.txt";
|
|
|
|
|
string resultPath = "/var/result/result.txt";
|
2023-10-10 16:40:13 +04:00
|
|
|
|
|
|
|
|
|
// Считываем числа из файла
|
|
|
|
|
int[] numbers = ReadNumbersFromFile(filePath);
|
|
|
|
|
|
|
|
|
|
// Ищем наибольшее число
|
|
|
|
|
int maxNumber = FindMaxNumber(numbers);
|
|
|
|
|
|
|
|
|
|
// Считаем количество таких чисел
|
|
|
|
|
int count = CountNumbers(numbers, maxNumber);
|
|
|
|
|
|
|
|
|
|
// Сохраняем результат в файл
|
|
|
|
|
SaveCountToFile(resultPath, count);
|
|
|
|
|
|
|
|
|
|
Console.WriteLine($"Максимальное число: {maxNumber}");
|
|
|
|
|
Console.WriteLine($"Количество макисмальных чисел: {count}");
|
|
|
|
|
|
|
|
|
|
static int[] ReadNumbersFromFile(string filePath)
|
|
|
|
|
{
|
|
|
|
|
string[] lines = File.ReadAllLines(filePath);
|
|
|
|
|
int[] numbers = Array.ConvertAll(lines, int.Parse);
|
|
|
|
|
return numbers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int FindMaxNumber(int[] numbers)
|
|
|
|
|
{
|
|
|
|
|
int maxNumber = int.MinValue;
|
|
|
|
|
foreach (int number in numbers)
|
|
|
|
|
{
|
|
|
|
|
if (number > maxNumber)
|
|
|
|
|
{
|
|
|
|
|
maxNumber = number;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return maxNumber;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int CountNumbers(int[] numbers, int targetNumber)
|
|
|
|
|
{
|
|
|
|
|
int count = 0;
|
|
|
|
|
foreach (int number in numbers)
|
|
|
|
|
{
|
|
|
|
|
if (number == targetNumber)
|
|
|
|
|
{
|
|
|
|
|
count++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void SaveCountToFile(string filePath, int count)
|
|
|
|
|
{
|
|
|
|
|
File.WriteAllText(filePath, count.ToString());
|
|
|
|
|
}
|