Advertisement
elynx

g64

Jan 17th, 2021
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int summa(int n) {
  6. int summa = 0;
  7. while (n != 0) {
  8. summa += n % 10; n /= 10;
  9. }
  10. return summa;
  11. }
  12. int main() {
  13. int n;
  14. cin >> n;
  15. int A[n];
  16. for (int i = 0; i < n; i++)
  17. cin >> A[i];
  18. for (int X = 0; X < n; X++)
  19. for (int j = n - 1; j > X; j--)
  20. if (summa(A[j]) > summa(A[j - 1]))
  21. swap(A[j], A[j - 1]);
  22. for (int Z = 0; Z < n; Z++)
  23. cout << A[Z] << " ";
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement