暴力求解可得
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <iostream>
#include <cstdio>
#include <sstream>
using namespace std;
int main(){
int N, i, k, kase=0;;
string line;
while(scanf("%d",&N)!=EOF){
kase++;
long long int S[N];
getchar();
//Input S[0]~S[N-1]
getline(cin,line);
i=0,k=0;
long long int x;
stringstream ss(line);
while(ss>>x){
S[i]=x;
i++;
}
int ok=0;
long long int max=0,tmp;
//count in brute-force
for(i=0;i<N;i++){
tmp = 1;
for(int j=i;j<N;j++){
tmp = tmp * S[j];
if(tmp > max) max = tmp;
}
}
cout << "Case #" << kase << ": The maximum product is "
<< max << "." ;
printf("\n\n");
}
return 0;
}
沒有留言:
發佈留言