#C12363. Sort and Merge Characters
Sort and Merge Characters
Sort and Merge Characters
You are given a string that contains both alphabetic characters and digits. Your task is to separate the letters from the digits, sort each group in ascending order, and then merge them so that the letters appear first followed by the digits.
For example, if the input string is 'd4c3b2a1', then after sorting the letters ('d', 'c', 'b', 'a') you obtain 'abcd' and after sorting the digits ('4', '3', '2', '1') you obtain '1234'. Merging these two sorted groups results in 'abcd1234'.
The problem can be mathematically described as follows:
Let \(S\) be the input string. Define two subsequences \(L\) and \(D\) such that:
[ L = { c \in S \mid c \text{ is an alphabet letter} } \quad \text{and} \quad D = { c \in S \mid c \text{ is a digit} } ]
Then, sort \(L\) and \(D\) in ascending order and output the concatenation \(\text{sorted}(L) \Vert \text{sorted}(D)\).
inputFormat
The input consists of a single line containing a string. The string may include both letters and digits. It is guaranteed that the string contains only letters (a-z, A-Z) and digits (0-9), and may be empty.
outputFormat
Output the resulting string after separating, sorting, and merging the letters and digits from the input. The letters should appear first followed by the digits.
## sampled4c3b2a1
abcd1234