您的位置:首页 > 其它

UVA 11059 Maximum Product

2017-08-05 10:36 417 查看
简单的题目,直接暴力遍历计算即可,时间复杂度O(n*n),具体实现见如下代码:

#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<deque>
using namespace std;

int n;

int main(){
int Case = 0;
while (cin >> n){
Case++;
vector<int> data;
long long int temp;
long long int res = 0;
for (int i = 0; i < n; i++){
int t;
cin >> t;
data.push_back(t);
}
for (int i = 0; i < n; i++){
temp =1;
for (int j = i ; j < n; j++){
temp *= data[j];
if (temp > res) res = temp;
}
}
cout << "Case #" << Case << ": The maximum product is " << res<<"." << endl << endl;
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: