Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace HW
- {
- class Program
- {
- static void Main(string[] args)
- {
- int sequenceLength = 1;
- int maxSequenceLength = 1;
- int arrayLength = 30;
- int arrayValues = 10;
- int index;
- int[] array = new int[arrayLength];
- Random random = new Random();
- for (int i = 0; i < array.Length; i++)
- {
- array[i] = random.Next(arrayValues);
- Console.Write(array[i] + " ");
- }
- int arrayValue = array[0];
- for (int i = 0; i < array.Length - 1; i++)
- {
- index = i;
- if(array[index] == array[++index])
- {
- sequenceLength++;
- }
- else
- {
- sequenceLength = 1;
- }
- if (maxSequenceLength <= sequenceLength)
- {
- arrayValue = array[i];
- maxSequenceLength = sequenceLength;
- }
- }
- Console.WriteLine($"\nМаксимальная длина последовательности = {maxSequenceLength}. Состоит из чисел = {arrayValue}");
- Console.ReadKey();
- }
- }
- }
Add Comment
Please, Sign In to add comment