C++20 sections · 1024 units
Open in Course

Helpful Maths - Algorithm

Breaking it down

Here's your approach:

1.1. Read the input string.

2.2. Create an empty vector to store digits.

3.3. Loop through each character in the string.

4.4. If the character is a digit, add it to the vector.

5.5. Sort the vector using sort().

6.6. Print the first digit.

7.7. For each remaining digit, print a plus sign followed by the digit.

8.8. Done. The solution uses filtering, sorting, and formatted output. You separate concerns: first extract digits, then sort them, then format the result. Each step is simple on its own.