Dr_Max_Experience

New task 6

Mar 18th, 2022 (edited)
841
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace HW
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int sequenceLength = 1;
  14.             int maxSequenceLength = 1;
  15.             int arrayLength = 30;
  16.             int arrayValues = 10;
  17.             int index;
  18.             int[] array = new int[arrayLength];
  19.             Random random = new Random();
  20.  
  21.             for (int i = 0; i < array.Length; i++)
  22.             {
  23.                 array[i] = random.Next(arrayValues);
  24.                 Console.Write(array[i] + " ");
  25.             }
  26.  
  27.             int arrayValue = array[0];
  28.  
  29.             for (int i = 0; i < array.Length - 1; i++)
  30.             {
  31.                 index = i;
  32.  
  33.                 if(array[index] == array[++index])
  34.                 {
  35.                     sequenceLength++;
  36.                 }
  37.                 else
  38.                 {
  39.                     sequenceLength = 1;
  40.                 }
  41.  
  42.                 if (maxSequenceLength <= sequenceLength)
  43.                 {
  44.                     arrayValue = array[i];
  45.                     maxSequenceLength = sequenceLength;
  46.                 }
  47.             }
  48.  
  49.             Console.WriteLine($"\nМаксимальная длина последовательности = {maxSequenceLength}. Состоит из чисел = {arrayValue}");
  50.             Console.ReadKey();
  51.         }
  52.     }
  53. }
Add Comment
Please, Sign In to add comment