嗯大家放心大胆的模拟~
C++ 代码
#include <cstdio>
const int N = 1010;
int arr[N];
int cnt;
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++ i) scanf("%d", &arr[i]);
for (int i = 1; i < n - 1; ++ i) {
if (arr[i - 1] > arr[i] && arr[i] < arr[i + 1]) cnt ++;
if (arr[i - 1] < arr[i] && arr[i] > arr[i + 1]) cnt ++;
}
printf("%d", cnt);
return 0;
}