zl程序教程

您现在的位置是:首页 >  其它

当前栏目

【例题 7-2 UVA - 11059】Maximum Product

UVa maximum product 例题
2023-09-14 09:03:45 时间

【链接】 我是链接,点我呀:)
【题意】

在这里输入题意

【题解】

C语言for循环练习题

【代码】

/*
  	1.Shoud it use long long ?
  	2.Have you ever test several sample(at least therr) yourself?
  	3.Can you promise that the solution is right? At least,the main ideal
  	4.use the puts("") or putchar() or printf and such things?
  	5.init the used array or any value?
  	6.use error MAX_VALUE?
*/

#include <bits/stdc++.h>
using namespace std;

int n;
int a[100];

int main(){
	#ifdef LOCAL_DEFINE
	    freopen("F:\\c++source\\rush_in.txt", "r", stdin);
	    freopen("F:\\c++source\\rush_out.txt", "w", stdout);
	#endif
	ios::sync_with_stdio(0),cin.tie(0);
        int kase = 0;
    while (cin >>n){
        kase++;
        cout << "Case #"<<kase<<": The maximum product is ";
        for (int i = 1;i <= n;i++) cin >> a[i];

        long long ans = 0;
        for (int i = 1;i <= n;i++)
        {
            long long temp = 1;
            for (int j = i;j<= n;j++){
                temp = (temp*1LL*a[j]);
                ans = max(ans,temp);
            }
        }

        cout <<ans<<"."<<endl;
        cout << endl;
    }

	return 0;
}