网址如下:
Maximum Product - UVA 11059 - Virtual Judge (vjudge.net)
(第三方网站)
简单枚举题,枚举就行,只是要注意数字太大导致“爆了”,用个long long int来记录
不过话说回来,关于数字过大的题最近都没怎么做了,上学期刚开学的时候做得倒是挺多,算是给C语言入门的一道小坎子吧
代码如下:
#include<cstdio>
typedef long long LL;
const int maxn = 18;
int S[maxn];LL svm(int begin, int end){LL tmp = 1;while(begin < end) tmp *= S[begin++];return tmp;
}int main(void)
{int N, kase = 0;while(scanf("%d", &N) == 1){LL maxnum = 0;for(int i = 0; i < N; i++) scanf("%d", &S[i]);for(int begin = 0; begin < N; begin++)for(int end = begin + 1; end <= N; end++){LL num = svm(begin, end);maxnum = maxnum > num ? maxnum : num;}printf("Case #%d: The maximum product is %lld.", ++kase, maxnum);putchar('\n'); putchar('\n');}return 0;
}