#include <iostream>
using namespace std;
unsigned DigitSum( unsigned x ) {
unsigned sum = 0;
while ( x != 0 ) {
sum += x % 10;
x /= 10;
}
return sum;
}
bool Comparison( const unsigned a, const unsigned b ) {
return DigitSum( a ) < DigitSum( b );
}
// третий параметр указатель на функцию сравнения для сортировки
void InsertionSort( unsigned long *arr, size_t size, bool (*compareFunc)( const unsigned, const unsigned ) ) {
for ( size_t i = 1; i < size; ++i )
for ( size_t j = i; j > 0 && Comparison( arr[ j - 1 ], arr[ j ] ); --j )
swap( arr[ j - 1 ], arr[ j ] );
}
int main() {
const size_t maxCount = 10000;
unsigned long* arr = new unsigned long[ maxCount ];
size_t count = 0;
cin >> count;
for ( size_t i = 0; i < count; ++i ) {
cin >> arr[ i ];
}
// сортируем массив, указывая какая функция для сравнения элементов используется
InsertionSort( arr, count, Comparison );
for ( size_t i = 0; i < count; ++i )
cout << arr[ i ] << " ";
delete[] arr;
return 0;
}
дайте 5 звёзд позязя