fork download
  1. #include<set>
  2. #include<iostream>
  3. using namespace std;
  4.  
  5. struct comp__f {
  6. bool operator() (const pair<double, int>& lhs, const pair<double, int>& rhs) const{
  7. return (lhs.second != rhs.second) && (lhs.first < rhs.first);
  8. }
  9. };
  10.  
  11. int main()
  12. {
  13. set<pair<double, int>, comp__f> s;
  14. s.insert(make_pair(10.234, 1));
  15. s.insert(make_pair(20.123, 2));
  16. s.insert(make_pair(10.2, 1));
  17. s.insert(make_pair(30.33, 3));
  18. s.insert(make_pair(20.123, 1));
  19.  
  20. for(auto entry : s)
  21. cout << entry.first << " - " << entry.second << endl;
  22.  
  23. return 0;
  24. }
Success #stdin #stdout 0s 4336KB
stdin
Standard input is empty
stdout
10.234 - 1
20.123 - 2
30.33 - 3