Advertisement
Legiomax

C#_3_subarray_duplicates_numbers

Jan 27th, 2024
1,189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 KB | Software | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace C_Ijun
  9. {
  10.     internal class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             Random random = new Random();
  15.  
  16.             int lowRangeRandom = 5;
  17.             int highRangeRandom = 10;
  18.             int duplicatesNum = lowRangeRandom;
  19.  
  20.             int localCountDuplicates = 1;
  21.             int maxCountDuplicates = 1;
  22.  
  23.             int[] numbers = new int[30];
  24.  
  25.             for (int i = 0; i < numbers.Length; i++)
  26.             {
  27.                 numbers[i] = random.Next(lowRangeRandom, highRangeRandom);
  28.             }
  29.  
  30.             Console.WriteLine("Исходная матрица.\n");
  31.  
  32.             for (int i = 0; i < numbers.Length; i++)
  33.             {
  34.                 Console.Write(numbers[i] + " ");
  35.             }
  36.  
  37.             for (int i = 0; i < numbers.Length - 1; i++)
  38.             {
  39.                 if (numbers[i] != numbers[i+1])
  40.                 {
  41.                     localCountDuplicates = 1;
  42.                 }
  43.                 else
  44.                 {
  45.                     localCountDuplicates++;
  46.  
  47.                     if (localCountDuplicates > maxCountDuplicates)
  48.                     {
  49.                         duplicatesNum = numbers[i];
  50.                         maxCountDuplicates++;
  51.                     }
  52.                 }
  53.             }
  54.  
  55.             Console.WriteLine($"\nСамая длинная строка повторов:\n{duplicatesNum}\n" +
  56.                 $"Число повторов:\n{maxCountDuplicates}");
  57.             Console.ReadKey();
  58.         }
  59.     }
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement