輸入n個元素的序列s,找出一個連續序列的最大乘積
分析:資料較小,直接O(n^2)可得出,用 long long
注意:printf輸出 long long 時要用%lld ,好像LINUX系統的原因,win系統要用%I64d ,因為我一直用%I64d WA好多次
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define LL long long
int main()
{
int N,s[20];
int p=0,flag=1;
while(scanf("%d",&N)!=EOF){
for(int i=0;i<N;i++)
scanf("%d",&s[i]);
LL maxn=0;
for(int i=0;i<N;i++){
LL temp=1;
for(int j=i;j<N;j++){
temp*=s[j];
if(temp>maxn) maxn=temp;
}
}
if(maxn<0)maxn=0;
// printf("Case #%d: The maximum product is %lld.\n\n",flag++,maxn);
printf("Case #%d: The maximum product is %I64d.\n\n",flag++,maxn);
}
return 0;
}