Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

#include <iostream>

using namespace std;

int f(int n, int a[])


{
if (a[0] > a[1])
{
for (int i = 2; i < n; i++)
{
if (a[i - 1] < a[i])
return -1;
}
return 2;
}
else if (a[0] < a[1])
{
for (int i = 2; i < n; i++)
{
if (a[i - 1] > a[i])
{
return -1;
}
}
return 1;
}
else
{
for (int i = 2; i < n; i++)
{
if (a[i] != a[i - 1])
return -1;
}
return 0;
}
}

int main()
{
int n = 5, a[] = { 1, 1, 3, 1, 1 };
cout << f(n, a);

return 0;
}

You might also like