Skip to content

Instantly share code, notes, and snippets.

@aKKKo
Created May 10, 2025 12:14
Show Gist options
  • Save aKKKo/1c48605b4415c883a65681f055f9d2b5 to your computer and use it in GitHub Desktop.
Save aKKKo/1c48605b4415c883a65681f055f9d2b5 to your computer and use it in GitHub Desktop.
Подмассив повторений чисел
using System;
namespace Subarray
{
class Program
{
static void Main(string[] args)
{
int arrayLength = 30;
int[] numbers = new int[arrayLength];
Random random = new Random();
int maxNumber = 10;
int currentNumber = numbers[0];
int repetitionСount = 0;
int maxRepetitionСount = 0;
int numberWithMaxRepetitionСount = 0;
Console.Write("Массив - ");
for (int i = 0; i < numbers.Length; i++)
{
int randomNumber = random.Next(maxNumber);
numbers[i] = randomNumber;
Console.Write(numbers[i] + " ");
}
for (int i = 0; i < numbers.Length; i++)
{
if (currentNumber == numbers[i])
{
repetitionСount++;
if (maxRepetitionСount < repetitionСount)
{
maxRepetitionСount = repetitionСount;
numberWithMaxRepetitionСount = currentNumber;
}
}
else
{
currentNumber = numbers[i];
repetitionСount = 1;
}
}
Console.WriteLine($"\nЧисло: {numberWithMaxRepetitionСount} | Повторений подряд: {maxRepetitionСount}");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment