#K66467. Sorted Number String

    ID: 32427 Type: Default 1000ms 256MiB

Sorted Number String

Sorted Number String

Given a string s consisting solely of digits, your task is to rearrange its digits in non-decreasing order. After sorting, all leading zeros must be removed, so that the resulting string represents the smallest possible number. In case the input is empty or the result contains no non-zero digits, output "0".

Note: The answer should be computed by reading the input from stdin and writing to stdout. For example:

  • If s = "340210", the sorted result is "1234".
  • If s = "0000310", the result after removing leading zeros is "13".
  • If s = "000000" or an empty string is given, the output should be "0".

The underlying idea is to use simple string manipulation and sorting techniques. In mathematical notation, if you let \( D = \{d_1, d_2, \ldots, d_n\} \) be the multiset of digits, then the answer is given by:

[ \text{result} = \begin{cases} \text{concatenate}(\text{sorted}(D)) \setminus \text{leading zeros}, & \text{if non-empty};\ "0", & \text{otherwise}. \end{cases} ]

inputFormat

Input is provided as a single line from stdin containing a string of digits. The string may be empty.

outputFormat

Output the smallest possible number formed by sorting the digits of the input string and removing any leading zeros. The result should be printed to stdout.## sample

340210
1234