Write a program, which finds the maximal sequence of consecutively placed increasing integers. Example: {3, 2, 3, 4, 2, 2, 4} ? {2, 3, 4}.
I write this program but when i enter n=5 and 2 5 6 7 6 isn't work :(
i'm beginner in c# so...
Sorry for my bad english i am Romanian
static void Main()
{
Console.Write("n=");
int n = int.Parse(Console.ReadLine());
int[] a = new int [n];
for (int i = 0; i < n; i++)
{
Console.Write("a[{0}]=", i);
a[i] = int.Parse(Console.ReadLine());
}
Console.WriteLine("maximal sequence");
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (a[i] {
Console.WriteLine(a[i]);
break;
}
}
}
}
Loading
VulpesPosted Jan 28, 2015, 2:34 PM
So. if you have {1, 2, 4, 3, 2, 3, 7, 9} then the maximal sequence will be {2, 3, 7, 9} because it's longer than {1, 2, 4}.
I've further assumed that if there is more than one maximal sequence, then the first one will be returned. So, if you have, {8, 9, 10, 7, 1, 2, 3} then the maximal sequence returned will be {8, 9, 10} rather than {1, 2, 3} because it's the first one in the array.
On that basis, the following should work: