#include <iostream>
#include <string>
usingnamespace std;
int main()
{
string outcomes[] = { "Non-monotonic", "Descending", "Flat", "Ascending" };
int a, b, state = 0;
cin >> a;
while ( cin >> b && b != 0 )
{
int test = ( b > a ) - ( b < a );
if ( state == 0 ) state = test;
elseif ( state * test < 0 )
{
state = -2;
break;
}
a = b;
}
cout << outcomes[state+2] << '\n';
}
Thanks, but your code is too complicated. I must resolve with while, if, else if.
??? That is simple code. It only uses the allowed while, if/else, conditions and assignments. Nothing complicated and doesn't use any of the STL algorithms.
Is good, but 1 1 1 2 0 => ascending but in this exemple is neither or 9 9 8 0 same.
Neither should only display if no1 is 0 or when the elements in the string are equal.