NikaBang

ДЗ: Подмассив повторений чисел

Oct 20th, 2025 (edited)
1,352
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | Gaming | 0 0
  1. internal class Program
  2. {
  3.     static void Main(string[] args)
  4.     {
  5.         int[] numbers = new int[30];
  6.         int minRandom = 1;
  7.         int maxRandom = 6;
  8.         int repeatingNumber = 0;
  9.         int startCountRepetition = 1;
  10.         int countRepetition = startCountRepetition;
  11.         int maxCountRepetition = startCountRepetition;
  12.  
  13.         Random random = new Random();
  14.  
  15.         Console.Write("Массив: ");
  16.  
  17.         for (int i = 0; i < numbers.Length; i++)
  18.         {
  19.             numbers[i] = random.Next(minRandom, maxRandom);
  20.             Console.Write(numbers[i] + " ");
  21.         }
  22.  
  23.         for (int i = 0; i < numbers.Length - 1; i++)
  24.         {
  25.             if (numbers[i] == numbers[i+1])
  26.             {
  27.                 countRepetition++;
  28.  
  29.                 if (countRepetition > maxCountRepetition)
  30.                 {
  31.                     maxCountRepetition = countRepetition;
  32.                     repeatingNumber = numbers[i];
  33.                 }
  34.             }
  35.             else
  36.             {
  37.                 countRepetition = startCountRepetition;
  38.             }
  39.         }
  40.  
  41.             if (maxCountRepetition == startCountRepetition)
  42.             {
  43.                 Console.WriteLine("в этом массиве нет повторяющихся чисел рядом.");
  44.             }
  45.             else
  46.             {
  47.                 Console.WriteLine($"число {repeatingNumber} повторяется {maxCountRepetition} раза подряд.");
  48.             }
  49.  
  50.         Console.ReadKey();
  51.     }
  52. }
Advertisement
Comments
  • User was banned
Add Comment
Please, Sign In to add comment