#K6626. Rearrange Alphabets and Digits
Rearrange Alphabets and Digits
Rearrange Alphabets and Digits
You are given a string s
consisting of lowercase English letters and digits. Your task is to rearrange the string in such a way that all alphabets appear before all digits, while preserving the original relative order of the characters in each group.
In other words, if we denote the input string as \[ s = s_1 s_2 \ldots s_n, \] then let \(A\) be the subsequence of all letters and \(D\) be the subsequence of all digits in \(s\), both preserving their original order. The output should be the concatenation \(A\) followed by \(D\).
Example:
- For
s = "3a2b5c1"
, the output should be "abc3251". - For
s = "a1b2c3d4"
, the output should be "abcd1234".
inputFormat
The input consists of a single string s
read from the standard input. The string s
contains only lowercase alphabets and digits. It is guaranteed that s
is non-empty.
outputFormat
Print the rearranged string to the standard output such that all alphabets in s
appear first (in the same order as in the input) followed by all digits (also in their original order).
3a2b5c1
abc3251