Maximum Product (UVA - 11059 )

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
int n;
int a[20];
long long mul=1;
long long maxx=0;
int num=0;
while(cin>>n&&n!=0)
{
maxx=0;
for(int i=0;i<n;i++)
cin>>a[i];
{
for(int i=0;i<n;i++)
{
mul=1;
for(int j=i;j<n;j++)
{
mul*=a[j];
maxx=max(mul,maxx);
}
}
if(maxx<=0)
{
num++;
cout<<"Case #"<<num<<":"<<" The maximum product is "<<"0"<<"."<<endl;
cout<<endl;
}
else
{
num++;
cout<<"Case #"<<num<<":"<<" The maximum product is "<<maxx<<"."<<endl;
cout<<endl;
}

}
}
return 0;
}

posted on 2019-03-17 16:58  灬旧人灬  阅读(97)  评论(0编辑  收藏  举报