#include <cstdio> int main() { int n, p = 0, q = 0, u = 0, v = 0; scanf("%i", &n); for (int i = 0; i<n; i++) { int a, b; scanf("%i", &a); if (u++ && (i%2? a>=b: a<=b)) p++, u = 0; if (v++ && (i%2? a<=b: a>=b)) q++, v = 0; b = a; } printf("%i\n", p<q? p: q); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #include <cstdio> int main() { int n, p = 0, q = 0, u = 0, v = 0; scanf("%i", &n); for (int i = 0; i<n; i++) { int a, b; scanf("%i", &a); if (u++ && (i%2? a>=b: a<=b)) p++, u = 0; if (v++ && (i%2? a<=b: a>=b)) q++, v = 0; b = a; } printf("%i\n", p<q? p: q); return 0; } |