fork download
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. int main()
  5. {
  6. std::vector<int> data {100, 80, 90, 100, 80, 60};
  7.  
  8. std::sort( data.begin(), data.end() );
  9. for( auto it = data.begin(); it != data.end(); ) {
  10. auto next = std::upper_bound( std::next( it ), data.end(), *it );
  11. auto newval = *it / std::distance( it, next );
  12. std::fill( it, next, newval );
  13. it = next;
  14. }
  15.  
  16. for( auto i : data )
  17. std::cout << i << " ";
  18. std::cout << std::endl;
  19. }
  20.  
Success #stdin #stdout 0s 3472KB
stdin
Standard input is empty
stdout
60 40 40 90 50 50