UVA11059MaximumProduct

来源:互联网 发布:最优化第二版课后答案 编辑:程序博客网 时间:2024/06/08 07:00
//UVA11059MaximumProduct#include<cstdlib>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>//#define LOCALusing namespace std;int main() {long long MAX = 0;int n = 0;int kase = 0;    #ifdef LOCAL    freopen("UVA11059in.txt", "r", stdin);    freopen("UVA11059out.txt", "w", stdout);    #endifwhile(scanf("%d", &n) == 1) {long long cnt = 1, tmp = 1;MAX = 0;long long a[30];for(int i = 0; i < n; i++) scanf("%lld", &a[i]);for(int i = 0; i < n; i++) {//i, j 遍历所有子列的起点和终点 for(int j = i; j < n; j++) {    tmp = 1;    for(int k = i; k <= j; k++) tmp *= a[k];MAX = max(tmp, MAX); } }printf("Case #%d: The maximum product is %lld.\n\n", ++kase, MAX);}return 0;}

原创粉丝点击