Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Problem5MaxIncreasingSequence
- {
- static void Main()
- {
- int size = int.Parse(Console.ReadLine());
- int[] arr = new int[size];
- int max = 1;
- int count = 1;
- int start = 0;
- for (int i = 0; i < arr.Length; i++)
- {
- arr[i] = int.Parse(Console.ReadLine());
- }
- for (int i = 0; i < arr.Length-1; i++)
- {
- if(arr[i]+1 == arr[i+1])
- {
- count++;
- if (count > max)
- {
- max = count;
- start = arr[i+1];
- }
- }
- else
- {
- count = 1;
- }
- }
- if (max == 1)
- {
- Console.WriteLine("This sequence doesn`t have a maximal sequence of increasing elements. ");
- }
- else
- {
- Console.Write("The maximal sequence of increasing elements is: " + max + ": ");
- for (int i = max; i > 0; i--)
- {
- Console.Write((start-i + 1) + " ");
- }
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement