Sorting digits of an integer

前端 未结 9 1276
日久生厌
日久生厌 2020-12-16 01:26

You are given an integer 51234 (say) we need to sort the digits of a number the output will be 12345.

How to do it without using array ?

9条回答
  •  情深已故
    2020-12-16 02:20

    You don't need to write a program at all, just do it with shell commands:

    echo "51234" | sed 's+\(.\)+\1\n+g' | sort | tr -d '\n'
    

提交回复
热议问题