#include <iostream>
#include <set>
#include <string>
struct Person {
std::string name;
int age;
bool operator<(const Person& other) const {
return age < other.age;
}
};
// Custom comparator for descending order
struct PersonComparator {
bool operator()(const Person& a, const Person& b) const {
return a.age > b.age;
}
};
int main() {
std::set<Person, PersonComparator> people;
people.insert({"Alice", 30});
people.insert({"Bob", 25});
people.insert({"Charlie", 35});
people.insert({"David", 28});
for (const auto& person : people) {
std::cout << person.name << ": " << person.age << std::endl;
}
return 0;
}