代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <deque>
#include <list>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <iterator>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double E = exp(1.0);
const int MOD = 1e9+7;
const int MAX = 1e3+5;
int n;
int sale[MAX];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
while(cin >> n)
{
for(int i = 1; i <= n; i++)
{
cin >> sale[i];
}
int sum = 0;
for(int i = 2; i <= n - 1; i++)
{
if((sale[i-1] > sale[i] && sale[i+1] > sale[i]) || (sale[i-1] < sale[i] && sale[i+1] < sale[i]))
sum++;
}
cout << sum << endl;
}
return 0;
}