fork(1) download
  1. #include <iostream>
  2. #include<set>
  3. using namespace std;
  4.  
  5. class Athlete{
  6. public:
  7. string n;
  8. double t;
  9. Athlete(string n, double t) : n(n), t(t) {}
  10. bool operator< (const Athlete a)const {
  11. return t < a.t;
  12. }
  13. };
  14.  
  15. int main(){
  16. set<Athlete> s;
  17. set<Athlete>::iterator iter;
  18. s.insert(Athlete("James", 45.8)); s.insert(Athlete("Alex", 51.9));
  19. s.insert(Athlete("Nikolas", 47.9)); s.insert(Athlete("Luka", 49.6));
  20. for (const auto& athlete : s) {
  21. cout << athlete.n << " - " << athlete.t << " s" << endl;
  22. }
  23. }
Success #stdin #stdout 0s 5296KB
stdin
Standard input is empty
stdout
James - 45.8 s
Nikolas - 47.9 s
Luka - 49.6 s
Alex - 51.9 s