Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _07Problem_MaxSequenceOfIncreasingElements
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] inputNumbers = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
- int currentLength = 0;
- int startPosition = 0;
- int bestLength = 0;
- int endOfLoop = inputNumbers.Length - 2;
- for (int i = 0; i <= endOfLoop; i++)
- {
- if (inputNumbers[i] <= inputNumbers[i + 1] - 1)
- {
- currentLength++;
- }
- else
- {
- if (currentLength > bestLength)
- {
- bestLength = currentLength;
- startPosition = i - bestLength;
- }
- currentLength = 0;
- }
- if (i == inputNumbers.Length - 2)
- {
- if (currentLength > bestLength)
- {
- startPosition = i + 1 - currentLength;
- bestLength = currentLength;
- }
- }
- }
- int endPosition = startPosition + bestLength;
- for (int i = startPosition; i <= endPosition; i++)
- {
- Console.Write(inputNumbers[i] + " ");
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement