vector找最大值 最小值
来源:互联网 发布:php 金额 格式化 编辑:程序博客网 时间:2024/05/22 03:51
参考别人的代码:
#include <iostream>
#include <vector>
#include <algorithm>
using
namespace
std;
struct
VectorPred
{
bool
operator()(
const
vector<
int
>& lhs,
const
vector<
int
>& rhs)
{
return
*max_element(lhs.begin(), lhs.end()) < *max_element(rhs.begin(), rhs.end());
}
};
int
main()
{
int
testArray1[5] = {3, 6, 8, 2, 1};
int
testArray2[5] = {3, 6, 8, 10, 1};
int
testArray3[5] = {1, 6, 8, 2, 100};
vector<
int
> vec1(testArray1, testArray1 + 5);
vector<
int
> vec2(testArray2, testArray2 + 5);
vector<
int
> vec3(testArray3, testArray3 + 5);
vector<vector<
int
> > testData;
testData.push_back(vec1);
testData.push_back(vec2);
testData.push_back(vec3);
vector<vector<
int
> >::iterator maxIt = max_element(testData.begin(), testData.end(), VectorPred());
int
maxElement = *max_element(maxIt->begin(), maxIt->end());
cout << maxElement << endl;
}
自己的代码:
struct VectorPred
{
bool operator()(const vector<int>& lhs, const vector<int>& rhs)
{
return *max_element(lhs.begin(), lhs.end()) < *max_element(rhs.begin(), rhs.end());
}
};
struct VectorPred2
{
bool operator()(const vector<int>& lhs, const vector<int>& rhs)
{
return *min_element(lhs.begin(), lhs.end()) < *min_element(rhs.begin(), rhs.end());
}
};
vector<vector<int> >::iterator maxIt = max_element(tp.begin(), tp.end(), VectorPred());
double maxElement = *max_element(maxIt->begin(), maxIt->end());
maxElement = maxElement / 255;
if (maxElement>0.99)
maxElement = 0.99;
cout <<"maxElement"<< maxElement << endl;
vector<vector<int> >::iterator minIt = min_element(tp.begin(), tp.end(), VectorPred2());
double minElement = *min_element(minIt->begin(), minIt->end());
minElement = (minElement / 255.0);
if (minElement<0.001)
minElement = 0.001;
cout <<"minElement"<< minElement << endl;
- vector找最大值 最小值
- 找最大值与最小值
- 找最大值和最小值
- 找最大值,最小值,累加
- 分治法找最大值最小值
- c++ 找最大值 最小值 函数
- 分而治之算法——找最大值最小值
- Code58 从ArrayList找最大值和最小值
- 数列特征(找最大值、最小值、和)
- vector 计算数组中的最大值 最小值
- C++ 数组或vector最大值最小值
- *min_element 神器第二弹 牛逼的找最大值 最小值
- 算法学习十五----找数组最大值和最小值
- 最大值&最小值
- 最大值-最小值
- 最大值,最小值
- 最大值最小值
- 找最小值
- EzRgnBtn 控件的四种显示状态:mouse down,mouse up,hot,enable
- ubuntu12.04 GX编译环境搭建
- PMD java代码质量检查
- List<>Copy
- leetcode 70. Climbing Stairs
- vector找最大值 最小值
- Node.js DNS模块
- CentOS7 安装mysql
- 4.21
- Cameyo 绿化软件
- TexturePacker 图片打包工具讲解与使用并且批处理打多包以及资源加密
- 【scikit-learn】06:make_blobs聚类数据生成器
- iOS 之 使用百度地图 (删除地图页面所有自己添加的标注)
- Android 利用第三方库实现下拉刷新 -android-Ultra-Pull-To-Refresh