fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. long long a[20],b[300];
  4. int main() {
  5. ios::sync_with_stdio(0);
  6. cin.tie(0);
  7. int n,z=0;
  8. while(cin>>n){
  9. z++;
  10. for(int i=0;i<n;i++){cin>>a[i];}
  11. int t=0;
  12. for(int i=0;i<n;i++){
  13.  
  14.  
  15.  
  16. long long x=1;
  17. for(int k=i;k<n;k++){
  18. x*=a[k];
  19. b[t]=x;
  20.  
  21. t++;}
  22.  
  23.  
  24.  
  25.  
  26. }
  27. sort(b,b+t);
  28. if(b[t-1]<0){cout<<"Case #"<<z<<": The maximum product is "<<0<<"."<<endl;}
  29. else{cout<<"Case #"<<z<<": The maximum product is "<<b[t-1]<<"."<<endl;}
  30. cout<<endl;
  31. }
  32.  
  33. }
Success #stdin #stdout 0.01s 5272KB
stdin
1
-1
3
-1
-1
-1
stdout
Case #1: The maximum product is 0.

Case #2: The maximum product is 1.