【发布时间】:2016-08-12 13:17:37
【问题描述】:
考虑:
vector<tuple<int, int, char>> array;
for(int i=0; i<m-1; i++)
{
long long int p;
cin >> p;
get<0>(x) = p; // Updated value
get<1>(x) = get<0>(x); // Real value
get<2>(x) = 'v';
array.push_back(x);
}
sort(array.begin(), array.end());
reverse(array.begin(), array.end());
// How can I get the maximum of the second field
// to to element with largest first field
// and then delete the tuple?
假设我有一个数据类型元组数组int, int, char。
例如,(5,5,h);(5,2,h);(5,7,v);(3,1,h);(3,7,h);(1,1 ,v)。
它已经根据第一个值按降序排序。现在我想找到包含最大第一个值和最大第二个值的部分?所以我只需要搜索前三部分。 有没有办法在这里使用 max() 或任何其他 STL 函数?
【问题讨论】:
-
据我所知,您并没有仅对第一个值进行排序;你对整个元组进行了排序。不是这样吗?