fork download
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <cmath>
  4.  
  5. using namespace std;
  6.  
  7. bool comp(double a, double b)
  8. {
  9. if (floor(a) < floor(b)) return true;
  10. else if (floor(a) > floor(b)) return false;
  11. else return fmod(a,1) > fmod(b,1);
  12. }
  13.  
  14. int main()
  15. {
  16. double a[] = {5.3, 6.4, 3.2, 5.1, 5.2 };
  17.  
  18. sort(a, a+5, comp);
  19.  
  20. for(auto x: a) cout << x << " ";
  21. }
  22.  
Success #stdin #stdout 0.01s 5464KB
stdin
Standard input is empty
stdout
3.2  5.3  5.2  5.1  6.4