-
Notifications
You must be signed in to change notification settings - Fork 38
/
1089.cpp
34 lines (28 loc) · 950 Bytes
/
1089.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 <stdio.h>
int main(){
int n,i,v[3],resultado,p0,p1;
while(1){
scanf("%d", &n);
if(n == 0) break;
resultado = 0;
scanf("%d", &v[0]);
scanf("%d", &v[1]);
if(n == 2){
if(v[0] != v[1]) resultado = 2;
}
else{
p0=v[0];
p1=v[1];
for(i = 2; i < n; i++){
scanf("%d", &v[2]);
if(((v[1]>v[0]) && (v[1]>v[2])) || ((v[1]<v[0]) && (v[1]<v[2]))) ++resultado;
v[0]=v[1];
v[1]=v[2];
}
if ((p0>p1 && p0>v[2]) || (p0<p1 && p0<v[2])) ++resultado;
if ((v[2]>v[0] && v[2]>p0) || (v[2]<v[0] && v[2]<p0)) ++resultado;
}
printf("%d\n", resultado);
}
return 0;
}