Advertisement
Guest User

Untitled

a guest
Feb 10th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. int len(int input){
  5. int i = 0;
  6. while(input>0){
  7. input/=10;
  8. i++;
  9. }
  10. return i;
  11. }
  12. int* intToList(int input,int cnt){
  13. int* res = (int*)malloc(sizeof(int)*cnt);
  14. int i = 0;
  15. while(input>0){
  16. *(res+i) = input%10;
  17. i++;
  18. input/=10;
  19. }
  20. return res;
  21. }
  22. int sortInt(input){
  23. int cnt = len(input);
  24. int* list = intToList(input,cnt);
  25. int i,j,swp;
  26. for(i=0;i<cnt;i++){
  27. for(j=0;j<cnt;j++){
  28. if(*(list+i)<*(list+j)){
  29. swp = *(list+i);
  30. *(list+i) = *(list+j);
  31. *(list+j) = swp;
  32. }
  33. }
  34. }
  35. int out = *(list);
  36. for(i=1;i<cnt;i++){
  37. out*=10;
  38. out+=*(list+i);
  39. }
  40. return out;
  41. }
  42. int main(){
  43. int input;
  44. scanf("%d",&input);
  45. printf("%d",sortInt(input));
  46. return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement