fork download
  1. #include <iostream>
  2. #include <utility>
  3. #include <algorithm>
  4.  
  5. std::vector< std::pair<double,double> > unoccupied( const std::vector<double>& seq )
  6. {
  7. constexpr double multiplier_after = 1.10 ;
  8. constexpr double multiplier_before = 0.90 ;
  9.  
  10. std::vector< std::pair<double,double> > result ;
  11.  
  12. if( seq.size() > 1 && std::is_sorted( std::begin(seq), std::end(seq) ) )
  13. {
  14. double prev = seq.front() * multiplier_after ;
  15. for( auto iter = ++std::begin(seq) ; iter != std::end(seq) ; ++iter )
  16. {
  17. double curr = *iter * multiplier_before ;
  18. if( curr > prev ) result.emplace_back( prev, curr ) ;
  19. prev = *iter * multiplier_after ;
  20. }
  21. }
  22.  
  23. return result ;
  24. }
  25.  
  26. int main()
  27. {
  28. for( const auto& p : unoccupied( { 2.0, 2.1, 2.13, 2.2, 3.5, 3.6, 3.9, 6.4, 7.0 } ) )
  29. std::cout << '[' << p.first << '-' << p.second << "] " ;
  30. std::cout << '\n' ;
  31. }
  32.  
Success #stdin #stdout 0s 3428KB
stdin
Standard input is empty
stdout
[2.42-3.15] [4.29-5.76]