#C5574. Reordering String: Letters and Digits
Reordering String: Letters and Digits
Reordering String: Letters and Digits
Given a string s that may contain both letters and digits, reorder the string so that all letters appear before all digits while preserving the original relative order of letters and digits.
For example, if s = "a1b2c3d4"
, the output should be "abcd1234"
.
Note: The input is provided via stdin
and the output should be printed to stdout
. Your solution should correctly process the string using efficient methods.
Formally, given a string \( s \), partition it into two subsequences \( L \) and \( D \), such that \( L \) consists of all letters in the original order and \( D \) consists of all digits in the original order. The final output is the concatenation \( L \Vert D \).
inputFormat
The input consists of a single line containing the string s. The string may include alphabetic characters and digits.
It is guaranteed that \(0 \leq |s| \leq 10^5\), where \(|s|\) denotes the length of the string.
outputFormat
Output a single line containing the reordered string where all letters appear first (in their original order) followed by all digits (in their original order).
## samplea1b2c3d4
abcd1234