Reorder the terms in an addition expression so they appear in nondecreasing order.
Problem
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.
Goal
Print the expression after sorting all numbers from smallest to largest.
Input Format
- A single string
srepresenting an expression of the forma+b+c+... - Each term is a single digit from
1to3or more generally a positive integer digit in the original problem style - Terms are separated by the character
+
Output Format
- Print one string: the same numbers arranged in nondecreasing order and joined by
+
Constraints
- The expression contains at least one number
- All numbers are valid positive integers in the original problem format
- You may assume the input is well-formed
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
Unlock deeper context for this problem
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.