1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| #include <iostream>
using namespace std;
const int N = 1010;
int n; int q[N];
int main() { cin >> n; for (int i = 0; i < n; i ++ ) cin >> q[i];
int res = 0; for (int i = 1; i < n - 1; i ++ ) { int a = q[i - 1], b = q[i], c = q[i + 1]; if (b < a && b < c || b > a && b > c) res ++ ; }
cout << res << endl; return 0; }
|