forked from zhuli19901106/poj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPOJ1492(AC).cpp
103 lines (97 loc) · 1.54 KB
/
POJ1492(AC).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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
using namespace std;
int main()
{
int n, a[100], tmp;
int i, j;
int upsum, upcount;
int downsum, downcount;
int flag;
while(true){
n = 0;
if(scanf("%d", &tmp) != 1){
break;
}else if(tmp == 0){
break;
}else{
a[n] = tmp;
++n;
while(true){
scanf("%d", &tmp);
if(tmp == 0){
break;
}else{
a[n] = tmp;
++n;
}
}
}
upsum = 0;
downsum = 0;
upcount = 0;
downcount = 0;
i = 0;
while(i + 1 < n && a[i] == a[i + 1]){
++i;
}
if(i + 1 < n){
//There is at least one sequence
if(a[i] < a[i + 1]){
j = i + 1;
i = 0;
flag = +1;
}else if(a[i] > a[i + 1]){
j = i + 1;
i = 0;
flag = -1;
}
while(true){
if(j + 1 >= n){
if(flag == +1){
upsum += (j - i);
++upcount;
}else if(flag == -1){
downsum += (j - i);
++downcount;
}
break;
}
if(flag == +1){
if(a[j] <= a[j + 1]){
++j;
}else{
upsum += (j - i);
++upcount;
flag = -1;
i = j;
j = j + 1;
}
}else if(flag == -1){
if(a[j] >= a[j + 1]){
++j;
}else{
downsum += (j - i);
++downcount;
flag = +1;
i = j;
j = j + 1;
}
}
}
}
printf("Nr values = %d: ", n);
if(upsum == 0){
printf("%.6f ", 0.0);
}else{
printf("%.6f ", 1.0 * upsum / upcount);
}
if(downsum == 0){
printf("%.6f\n", 0.0);
}else{
printf("%.6f\n", 1.0 * downsum / downcount);
}
}
return 0;
}