Let\'s say I have an array of ints {100, 80, 90, 100, 80, 60}
so I want to count those duplicates and save those counter for later. because each duplicate number sh
Here is algo to replace elements in place if you are allowed to modify sequence:
const auto begin = std::begin( data );
const auto end = std::end( data );
std::sort( begin, end );
for( auto it = begin; it != end; ) {
auto next = std::upper_bound( std::next( it ), end, *it );
auto newval = *it / std::distance( it, next );
std::fill( it, next, newval );
it = next;
}
demo on ideone
PS modified to make it compile with array as well.