Advertisement
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;
- class MaxIncreasingSequence
- {
- static void Main()
- {
- Console.WriteLine("Please enter the number of elements in your array:");
- int sizeOfArray = int.Parse(Console.ReadLine());
- int[] Array = new int[sizeOfArray];
- int currentLen = 1;
- int bestLen = 1;
- int bestLenIndex=0;
- for (int i = 0; i < sizeOfArray; i++)
- {
- Console.WriteLine("Please enter the elements for the array:");
- Array[i] = int.Parse(Console.ReadLine());
- if (i == 0)
- {
- continue;
- }
- if (Array[i] == Array[i - 1]+1)
- {
- currentLen++;
- }
- if (i == sizeOfArray - 1)
- {
- if (currentLen > bestLen)
- {
- bestLen = currentLen;
- bestLenIndex = i;
- }
- }
- if (Array[i] != Array[i - 1]+1 )
- {
- if (currentLen > bestLen)
- {
- bestLen = currentLen;
- bestLenIndex=i-1;
- }
- currentLen = 1;
- }
- }
- Console.WriteLine("The maximum sequence of increasing elements is:{0}", bestLen);
- Console.Write("The elements are: {");
- for (int i = bestLenIndex-bestLen+1; i <= bestLenIndex; i++)
- {
- if (i==bestLenIndex)
- {
- Console.WriteLine(Array[i]+"}");
- }
- else
- {
- Console.Write(Array[i] + ", ");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement