这道题的主要考点有两个,一个是枚举起点和终点,一个是int以及longlong的取值范围;
其中int的取值范围是2亿即 2*10^9, uint 取值是4*10^9
longlong的取值是是9*10^18
unsigned long long 的取值范围是18 * 10 ^18.
超过以上范围就需要去使用大数了
而且需要注意的一点就是,与使用longlong类型变量配套的变量也有可能使用longlong类型
附上AC代码
//这道题我一开始的想法是从一个数枚举到n个数,即第一次枚举所有的1位数,第二次枚举所有的2位数..... //刘汝佳的思路是枚举起点和终点 //经过比较就可以发现刘汝佳的方式的编程很简单,但是我的就很复杂oz //主要原因是我没有想到如何去枚举起点和终点 #include<cstdio> #include<iostream> using namespace std; int main() { #ifdef local freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif int num; int s[20]; int kase = 0; while(scanf("%d",&num) == 1) { for(int i = 0;i < num ; i++) { scanf("%d",&s[i]); } long long ans = 0; for(int i = 0;i < num;i++) { long long v = 1; for(int j = i;j < num;j++) { v = v * s[j]; if(v > ans) ans = v; } } cout<<"Case #"<<++kase<<": The maximum product is "; cout<<ans<<"."<<endl<<endl; } }