Created
May 10, 2025 12:14
-
-
Save aKKKo/1c48605b4415c883a65681f055f9d2b5 to your computer and use it in GitHub Desktop.
Подмассив повторений чисел
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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