Ответ:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int sumDigit(int c)
{
int sum = 0;
while(c)
sum += c % 10;
c /= 10;
}
return sum;
int main()
vector <int> vec;
int n;
cin >> n;
for(int i = 0; i < n; ++i)
int tmp;
cin >> tmp;
vec.push_back(tmp);
for(int i = 0; i < n - 1; ++i)
for(int j = i + 1; j < n; ++j)
if(sumDigit(vec[i]) < sumDigit(vec[j]))
swap(vec[i], vec[j]);
for(auto & ch : vec)
cout << ch << ' ';
return 0;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
Ответ:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int sumDigit(int c)
{
int sum = 0;
while(c)
{
sum += c % 10;
c /= 10;
}
return sum;
}
int main()
{
vector <int> vec;
int n;
cin >> n;
for(int i = 0; i < n; ++i)
{
int tmp;
cin >> tmp;
vec.push_back(tmp);
}
for(int i = 0; i < n - 1; ++i)
{
for(int j = i + 1; j < n; ++j)
{
if(sumDigit(vec[i]) < sumDigit(vec[j]))
{
swap(vec[i], vec[j]);
}
}
}
for(auto & ch : vec)
cout << ch << ' ';
return 0;
}