#K79752. Rearrange String: Digits to the Front
Rearrange String: Digits to the Front
Rearrange String: Digits to the Front
Given a string s that consists of both letters and digits, rearrange the string such that all the digits appear at the beginning followed by the letters. The relative order among the digits should be the same as in the original string, and the same applies to the letters. For example, for the string a1b2c3
, the output should be 123abc
.
The problem can be formally defined as follows:
Given a string \(s\), produce a new string \(t\) such that:
- All characters in \(t\) that are digits appear first in the same order they appear in \(s\).
- All the letters appear after the digits in the same relative order as in \(s\).
Note: The input string is guaranteed to only contain alphanumeric characters.
inputFormat
The input consists of a single line containing the string (s).
outputFormat
Output a single line containing the rearranged string.## sample
a1b2c3
123abc