您的位置:首页 > 其它

[UVA] 11059 Maximum Product

2017-03-02 21:35 375 查看
题目分析:暴力,直接枚举起点和终点,乘积最大不超过10的18次方,可以用long long 存下。

题目代码:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std ;

int s[50];

int main(){
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
int n;
int m=0;
int num=0;
while(scanf("%d",&n)!=EOF){

memset(s,0,sizeof(s));
long long max = 0;
for(int i = 1 ; i<= n ; i++){
scanf("%d",&s[i]);
}
long long ans = 1 ;
for(int i = 1 ; i <= n ; i++){
for(int j = i ;j <=n ;j++){
ans=1;
for(int t = i ; t <= j ;t++){
ans *= s[t];
}
if(ans>max){
max = ans ;
}
}
}
printf("Case #%d: The maximum product is %lld.\n\n",++num,max);
}
return 0 ;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  uva