#include <algorithm> #include <iostream> #include <iterator> #include <vector> #include <limits> #ifndef _countof #define _countof(arr) (sizeof(arr) / sizeof(*arr)) #endif struct item { int x; int y; }; bool gt(const item& f, const item& g) { return (f.y > g.y || f.y == g.y && f.x < g.x); } std::ostream& operator << (std::ostream& out, const item& g) { return out << g.x << ' ' << g.y; } int main() { item init[] = { {1, 34}, {2, 11}, {17, 2}, {18, 1}, {19, 5}, {20, 6}, {9001, 0}, {1111, 0}, {701, 0}, {111, 11} }; item z = { std::numeric_limits<int>::max(), 1 }; std::vector<item> arr(init, init + _countof(init)); std::sort(arr.begin(), arr.end(), gt); arr.erase(std::upper_bound(arr.begin(), arr.end(), z, gt), arr.end()); std::copy(arr.begin(), arr.end(), std::ostream_iterator<item>(std::cout, "\n")); return 0; } |