题意:给你一个数字序列,问有多少个数字小于它的左右两边的两个数(ai < ai - 1 and ai < ai + 1) 或 大于它的左右两边的两个数(ai > ai - 1 and ai > ai + 1),左右端点不算
思路:暴力。。。
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 5;
int n, a[MAXN];
int main()
{
while(~scanf("%d", &n))
{
for(int i = 0; i < n; i++) scanf("%d", &a[i]);
int ans = 0;
for(int i = 1; i < n - 1; i++)
{
if(a[i] < a[i - 1] && a[i] < a[i + 1] ||
a[i] > a[i - 1] && a[i] > a[i + 1])
ans++;
}
printf("%d\n",ans);
}
return 0;
}