fork download
  1. #include <iostream>
  2. using namespace std;
  3. bool yes(int a,int b){
  4. int su=0;
  5. if(a<0)a*=-1;
  6. while(a>0){
  7. su+=a%10;
  8. a/=10;
  9. }
  10. if(su<b)return false;
  11. else return true;
  12. }
  13. int main(){
  14. int n, c;
  15. cin>> n>>c;
  16. int* a= new int[n];
  17. for(int i=0;i<n;i++){
  18. cin>>a[i];
  19. }
  20. int p=0;
  21. for(int i=0;i<n;i++){
  22. if(yes(a[i],c)){
  23. int t=a[i];
  24. a[i]=a[p];
  25. a[p]=t;
  26. p++;
  27. }
  28. }
  29. for(int i =0;i<n;i++){
  30. cout<<a[i]<<" ";
  31. }
  32. delete[] a;
  33. return 0;
  34. }
Success #stdin #stdout 0.01s 5320KB
stdin
3
7
12
38
98
stdout
38 98 12