-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11496.cpp
34 lines (31 loc) · 912 Bytes
/
11496.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
int main() {
while(true) {
int n;
cin >> n;
if(n == 0)
break;
int i;
vector<int> sample(n);
for(i = 0; i < n; i++) {
cin >> sample[i];
}
int peaks = 0;
if( (sample[0] > sample[n-1] && sample[0] > sample[1]) ||
(sample[0] < sample[n-1] && sample[0] < sample[1]))
peaks++;
if( (sample[n-1] > sample[n-2] && sample[n-1] > sample[0]) ||
(sample[n-1] < sample[n-2] && sample[n-1] < sample[0]))
peaks++;
for(i = 1; i < n-1; i++) {
if( (sample[i] > sample[i+1] && sample[i] > sample[i-1]) ||
(sample[i] < sample[i+1] && sample[i] < sample[i-1]))
peaks++;
}
cout << peaks << endl;
}
return 0;
}