第七章部分例题最大乘积

思路:用数组存储

然后枚举起点和终点来创建子序列由于乘积很大所以要用long long 同时使用cout输出避免printf不同编译器的不同实现

 1 #include <cstdio>
 2 #include <algorithm>
 3 #include <iostream>
 4 
 5 using namespace std;
 6 
 7 long long const inf=-1e18;
 8 int s[20];
 9 
10 int main()
11 {
12     long long mu;
13     long long best=inf;
14 
15     cout<<best<<endl;
16 
17     int n;
18     cin>>n;
19 
20     for(int i=0;i<n;i++)
21         scanf("%d",&s[i]);
22 
23     for(int i=0;i<n;i++)
24         for(int j=n-1;j>=i;j--)
25         {
26             mu=1;
27 
28             for(int b=i;b<=j;b++)
29                 mu*=s[b];
30 
31             best=max(best,mu);
32         }
33 
34     cout<<best<<endl;
35 }
Yosoro
原文地址:https://www.cnblogs.com/tclan126/p/7403637.html