-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11059.cpp
More file actions
46 lines (44 loc) · 1.05 KB
/
11059.cpp
File metadata and controls
46 lines (44 loc) · 1.05 KB
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
#include <bits/stdc++.h>
int main() {
int a[18];
long long b[40], sum;
int i, j, last, k = 0, n;
while (scanf("%d", &n) == 1) {
k++;
for (i = 0; i < n; i++) scanf("%d", &a[i]);
j = 0;
sum = 1;
for (i = 0; i < n; i++) {
if (a[i] == 0) {
sum = 1;
} else {
sum *= a[i];
if (sum > 0) {
b[j] = sum;
j++;
}
}
}
sum = 1;
for (i = n - 1; i >= 0; i--) {
if (a[i] == 0) {
sum = 1;
} else {
sum *= a[i];
if (sum > 0) {
b[j] = sum;
j++;
}
}
}
sum = 1;
if (j == 0) {
printf("Case #%d: The maximum product is 0.\n\n", k);
} else {
std::sort(b, b + j);
j--;
printf("Case #%d: The maximum product is %lld.\n\n", k, b[j]);
}
}
return 0;
}