fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. bool Sum_Compare(int x,int y)
  6. {
  7. int tempx=x,tempy=y;
  8. int sumx=0,sumy=0;
  9.  
  10. while(tempx)
  11. {
  12. sumx+=tempx%10;
  13. tempx/=10;
  14. }
  15.  
  16. while(tempy)
  17. {
  18. sumhttps:
  19. tempy/=10;
  20. }
  21.  
  22. return sumx<sumy;
  23. }
  24.  
  25. int main()
  26. {
  27. int arr[]={0,1,20,40,22,88,975};
  28. int n=sizeof(arr)/sizeof(arr[0]);
  29.  
  30. sort(arr,arr+n,Sum_Compare);
  31.  
  32. for(auto& x:arr)
  33. cout<<x<<" ";
  34.  
  35. return 0;
  36. }
  37.  
Success #stdin #stdout #stderr 0.01s 5348KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Error: near line 3: near "using": syntax error
Error: near line 5: near "bool": syntax error
Error: near line 8: near "int": syntax error
Error: near line 10: near "while": syntax error
Error: near line 13: near "tempx": syntax error
Error: near line 14: unrecognized token: "}"
Error: near line 20: unrecognized token: "}"
Error: near line 23: unrecognized token: "}"
Error: near line 28: near "int": syntax error
Error: near line 30: near "sort": syntax error
Error: near line 32: near "for": syntax error
Error: near line 35: near "return": syntax error
Error: near line 36: unrecognized token: "}"