Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <set>
- #include <vector>
- #include <algorithm>
- using namespace std;
- struct Foo {
- int a, b, c;
- Foo(int a, int b, int c) : a(a), b(b), c(c) {}
- bool operator<(const Foo& rhs) const {
- return a < rhs.a;
- }
- friend ostream& operator<<(ostream&, const Foo&);
- };
- ostream& operator<<(ostream& stream, const Foo& foo) {
- stream << foo.a << ", " << foo.b << ", " << foo.c;
- return stream;
- }
- int main() {
- set<Foo> s;
- s.insert({ 1,2,3 });
- s.insert({ 1,3,4 });
- s.insert({ 2,3,1 });
- s.insert({ 2,4,6 });
- s.insert({ 3,5,2 });
- s.insert({ 1,5,7 });
- for (auto x : s) {
- cout << x << endl;
- }
- vector<Foo> v;
- std::copy(s.begin(), s.end(), std::back_inserter(v));
- std::sort (v.begin(), v.end(), [](const Foo& lhs, const Foo& rhs){ return (lhs.b == rhs.b) ? lhs.c > rhs.c : lhs.b > rhs.b; });
- for (auto x : v) {
- cout << x << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement