Reorder the terms in an addition expression so they appear in nondecreasing order.
You are given a simple arithmetic expression containing only single-digit positive integers separated by plus signs, such as 3+2+1. Your task is to rearrange the numbers so that the expression is sorted in nondecreasing order.
The + signs must remain between every pair of numbers, and the final result should contain the same numbers as the input, just in sorted order.
Print the expression after sorting all numbers from smallest to largest.
s representing an expression of the form a+b+c+...1 to 3 or more generally a positive integer digit in the original problem style++Example 1
Input
3+2+1
Output
1+2+3
Explanation
The numbers are rearranged into increasing order.
Example 2
Input
1+1+3+1
Output
1+1+1+3
Explanation
All terms are preserved, only their order changes.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.