思路:遍历数组,找到某个元素,即大于前面元素,又大于后面元素的个数
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
using namespace std;
//山峰统计
int main() {
string s;
getline(cin, s);
istringstream iss(s);
vector<int> moutain;
string temp;
while(getline(iss,temp,',')){
moutain.push_back(stoi(temp));
}
int count = 0;
for(int i = 1;i<moutain.size() - 1;i++){
if(moutain[i]>moutain[i-1]&&moutain[i]>moutain[i+1]){
count++;
}
}
int len = moutain.size() - 1;
if(len>1){
if(moutain[0]>moutain[1]){
count++;
}
if(moutain[len]>moutain[len-1]){
count++;
}
}
cout << count << endl;
}