参考别人的代码:
#include
#include
#include
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
int
> > testData;
testData.push_back(vec1);
testData.push_back(vec2);
testData.push_back(vec3);
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
{
return *max_element(lhs.begin(), lhs.end()) < *max_element(rhs.begin(), rhs.end());
}
};
struct VectorPred2
{
bool operator()(const vector
{
return *min_element(lhs.begin(), lhs.end()) < *min_element(rhs.begin(), rhs.end());
}
};
vector
double maxElement = *max_element(maxIt->begin(), maxIt->end());
maxElement = maxElement / 255;
if (maxElement>0.99)
maxElement = 0.99;
cout <<"maxElement"<< maxElement << endl;
vector
double minElement = *min_element(minIt->begin(), minIt->end());
minElement = (minElement / 255.0);
if (minElement<0.001)
minElement = 0.001;
cout <<"minElement"<< minElement << endl;