blob: 1fbeba9e96b7f22049c81ca08707ef576e182b50 (
plain)
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
|
#include <iostream>
using namespace std;
int main() {
int size;
int prev, next;
int picos;
cin>>size; // Primera lectura del tamaƱo fuera del bucle para primera comprobaciĆ³n
while (size != 0) {
int heights[size];
// Lee todas las alturas
for (int i = 0; i < size; i++) {
cin>>heights[i];
}
picos = 0;
// Comprueba todas las alturas
for (int i = 0; i < size; i++) {
prev = i-1;
if (prev < 0)
prev = size-1;
next = (i+1)%size;
if (heights[i] > heights[prev] && heights[i] > heights[next])
picos++;
}
cout<<picos<<endl;
cin>>size;
}
}
|