58 lines
1.5 KiB
C#
58 lines
1.5 KiB
C#
|
using System;
|
|||
|
using System.IO;
|
|||
|
|
|||
|
string filePath = "../var/data/data.txt";
|
|||
|
string resultPath = "../var/result/result.txt";
|
|||
|
|
|||
|
// Считываем числа из файла
|
|||
|
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());
|
|||
|
}
|