#C1803. Rearrange String: Alphabets First, Then Digits
Rearrange String: Alphabets First, Then Digits
Rearrange String: Alphabets First, Then Digits
You are given a string s
that consists of lowercase alphabets and digits. Your task is to rearrange the string so that all the alphabets appear first, in the order they appear in s
, followed by all the digits, also in the order they appear.
This means that if the string can be represented as
\( s = s_1 s_2 \dots s_n \)
and if we denote by \( A \) the subsequence of alphabets and by \( D \) the subsequence of digits (both preserving their original order), then the required output is:
\( A\;||\;D \)
where ||
denotes string concatenation.
For example:
- If
s = "a1b2c3"
, then the output should be"abc123"
. - If
s = "x9y8z7"
, then the output should be"xyz987"
.
inputFormat
The input consists of a single line that contains the string s
composed of lowercase alphabets and digits.
Note: There are no spaces in the input string.
outputFormat
Output the rearranged string where all alphabets appear first (preserving their order) followed by all digits (preserving their order).
## samplea1b2c3
abc123