-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmaxProduct.cpp
53 lines (49 loc) · 1.13 KB
/
maxProduct.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
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
ifstream fin("maxProduct.in");
ofstream fout("maxProduct.out");
int main()
{
int count = 0;
while (true)
{
++count;
int n = 0;
long long ans = 0;
fin >> n;
if (n == 0)
{
return 0;
}
vector<int> a(n);
for (int i = 0; i <= n - 1; ++i)
{
fin >> a[i];
}
for (int start = 0; start <= n - 1; ++ start)
{
for (int end = start; end <= n - 1; ++ end)
{
long long total = 1;
for (int i = start; i <= end; ++ i)
{
total *= a[i];
}
if (total > ans)
{
ans = total;
}
}
}
fout << "Case #" << count << ": The maximum product is " << ans << ".\n\n";
}
}