#C3678. Rearrange String
Rearrange String
Rearrange String
You are given a string containing tokens separated by spaces. Your task is to rearrange the string such that all tokens consisting solely of digits (i.e., numbers) appear before all other tokens (i.e., words). The relative order of the numbers and the relative order of the words must remain the same as in the input.
Input: A single line of input that may contain both numbers and words separated by spaces. The string can be empty.
Output: A single line string where all number tokens appear first (in the same order as they appeared in the input) followed by all word tokens (also in their original order).
Example:
If the input is "apple 1 banana 2 oranges 3 4 grapes", the output should be "1 2 3 4 apple banana oranges grapes".
inputFormat
A single line string s
containing tokens separated by spaces. The tokens may be numerical (containing only digits) or alphabetic words.
outputFormat
A single line string where all tokens that are numbers appear first, followed by all tokens that are words, with the order preserved from the input.
## sampleapple 1 banana 2 oranges 3 4 grapes
1 2 3 4 apple banana oranges grapes