此题链接单击这里
=================
求最大连续乘积,分别以每个数为起点。连续乘起点数后的数,每乘一个数判断一次(中间变量存储大的数),最后输出中间变量。
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
int N, l = 0;
while (cin >> N&&N)
{
int a[30];
long long sum;
for (int i = 0; i<N; i++)
cin >> a[i];
long long temp = a[0];
for (int i = 0; i<N; i++)
{
sum = a[i];
if (sum>temp)
temp = sum;
for (int j = i + 1; j<N; j++)
{
sum *= a[j];
if (sum>temp)
temp = sum;
}
}
if(temp<0)
temp=0;
printf("Case #%d: The maximum product is %lld.\n\n", ++l, temp);
}
return 0;
}
有问题联系企鹅791267032
邮箱地址….wutanrong@Hotmail.com