fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <utility>
  6.  
  7. using namespace std;
  8.  
  9. int sum(int s)
  10. {
  11. int k = 0;
  12. while (s != 0)
  13. {
  14. k += s % 10;
  15. s /= 10;
  16. }
  17. return k;
  18. }
  19.  
  20. bool f(int f1, int f2)
  21. {
  22. return sum(f1) < sum(f2);
  23. }
  24.  
  25. int main()
  26. {
  27. int n;
  28. vector<int> v;
  29. for (int i = 0; i < 3; i++)
  30. {
  31. cin >> n;
  32. v.push_back(n);
  33. }
  34. sort(v.begin(), v.end(), f);
  35. for (auto e : v)
  36. cout << e << ' ' << sum(e) << endl;
  37. }
Success #stdin #stdout 0.01s 5504KB
stdin
Standard input is empty
stdout
22070 11
22070 11
22070 11