Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. ifstream fin("sortcif.in");
  6. ofstream fout("sortcif.out");
  7.  
  8. int sumcif(int n)
  9. {
  10. int s=0;
  11. while(n)
  12. s+=n%10,n/=10;
  13. return s;
  14. }
  15.  
  16. int main()
  17. {
  18. int n, x[101];
  19. fin >> n;
  20. for(int i=1;i<=n;i++)
  21. fin >> x[i];
  22. for(int i=1;i<=n;i++)
  23. {
  24. for(int j=i;j<=n;j++)
  25. if(sumcif(x[i])>sumcif(x[j]))
  26. {
  27. int aux;
  28. aux=x[i];
  29. x[i]=x[j];
  30. x[j]=aux;
  31. }
  32. }
  33. for(int i=1;i<=n;i++)
  34. fout << x[i] << " ";
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement