UVa 11059 最大乘积

来源:互联网 发布:iphone6s网络设置 编辑:程序博客网 时间:2024/06/05 23:58
#include <iostream>

using namespace std;

long long MaxProduct(int *arr, int n)
{
    long long Max = 0;
    long long nowProduct;

    for(int i = 0; i < n-1; ++ i)
    {
        for(int j = 1; j < n; ++ j)
        {
            nowProduct = 1;

            for(int k = i; k <= j; ++ k)
                nowProduct *= arr[k];

            if(nowProduct > Max)
                Max = nowProduct;
        }
    }

    return Max;
}

int main()
{
    int arr[20];
    int n;

    cin >> n;
    for(int i = 0; i < n; ++ i)
        cin >> arr[i];

    cout << MaxProduct(arr, n) << endl;
    return 0;
}


1 0
原创粉丝点击