#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++)
cin >> v[i];
}
int sum = 0;
int num = v[i];
while (num > 0)
sum += num % 10;
num /= 10;
v[i] = sum;
sort(v.begin(), v.end(), greater<int>());
cout << v[i] << " ";
return 0;
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++)
{
cin >> v[i];
}
for (int i = 0; i < n; i++)
{
int sum = 0;
int num = v[i];
while (num > 0)
{
sum += num % 10;
num /= 10;
}
v[i] = sum;
}
sort(v.begin(), v.end(), greater<int>());
for (int i = 0; i < n; i++)
{
cout << v[i] << " ";
}
return 0;
}