解
遍历判断左右与其满足关系
int judge(int x, int y, int z) {
return (x < y && x < z) || (x > y && x > z);
}
//
// Created by 29273 on 2021-04-02.
//
#include "bits/stdc++.h"
using namespace std;
int a[1001];
int judge(int x, int y, int z) {
return (x < y && x < z) || (x > y && x > z);
}
int main() {
int n, res = 0;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 1; i < n - 1; i++) {
res += judge(a[i], a[i - 1], a[i + 1]);
}
cout << res << endl;
return 0;
}