Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class MaxIncreasSequence
- {
- static void Main()
- {
- Console.WriteLine("Please, Insert the length of the array!");
- int n = int.Parse(Console.ReadLine());
- // Read the array
- int[] array = new int[n];
- for (int i = 0; i < n; i++)
- {
- array[i] = int.Parse(Console.ReadLine());
- }
- // Compair
- int count = 0;
- int maxLength = 0;
- int getPossition = 0;
- for (int i = 0; i < array.Length - 1; i++)
- {
- if ((array[i] + 1) == (array[i + 1])) // if the condition of the task is "+1"
- // if (array[i] <= array[i + 1]) // if the condition of the task is "increese sequence"
- {
- count++;
- }
- else
- {
- count = 0;
- }
- if (count >= maxLength)
- {
- maxLength = count;
- getPossition = i + 1 - count;
- }
- }
- maxLength += 1;
- // Print
- for (int i = getPossition; i < getPossition + maxLength; i++)
- {
- Console.Write(array[i] + " ");
- }
- Console.WriteLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement