#include #include #include int tstSeq(FILE* f); int main() { FILE* in = fopen("input.txt", "r"); if (in == NULL) { perror("Could not open input file"); return (-1); } int res = tstSeq(in); fclose(in); FILE* out = fopen("output.txt", "w"); if (in == NULL) { perror("Could not open output file"); return (-1); } fprintf(out, "%d\n", res); fclose(out); return 0; } int tstSeq(FILE* f) { int ascending = 0; int len = 0; double last = 0.; // Actually, the initial value is not used int a; while (fscanf(f, "%d", &a) == 1) { if (len > 0) { if (ascending > 0) { if (a <= last) { ascending = 0; break; } } else if (ascending < 0) { if (a >= last) { ascending = 0; break; } } else { assert(ascending == 0 && len == 1); // The second element if (a > last) ascending = 1; else if (a < last) ascending = (-1); else break; // first 2 elements are equal } } last = a; ++len; } return ascending; }