CSP-201604-1-折点计数
解题代码
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int n, pointSum;
int main() {
cin >> n;
vector<int>myData(n);
for (int i = 0; i < n; i++)
{
cin >> myData[i];
}
// 统计折点
for (int i = 1; i < n - 1; i++)
{
if ((myData[i] > myData[i - 1] && myData[i] > myData[i + 1]) ||
(myData[i] < myData[i - 1] && myData[i] < myData[i + 1]))
{
pointSum++;
}
}
cout << pointSum;
return 0;
}