Advertisement
a53

SortSum

a53
Feb 13th, 2022
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <algorithm>
  4. using namespace std;
  5. const int nm=1e7;
  6.  
  7. int sum(int x)
  8. {
  9. int s=0;
  10. while(x)
  11. s+=x%10,x/=10;
  12. return s;
  13. }
  14.  
  15. int main()
  16. {
  17. int x,n=0,a[nm/10+2];
  18. ifstream fin("sortsum.in");
  19. while(fin>>x)
  20. a[n++]=sum(x)*nm+nm-x;
  21. sort(a,a+n);
  22. ofstream fout("sortsum.out");
  23. for(int i=0;i<n;++i)
  24. fout<<nm-a[i]%nm<<' ';
  25. return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement