#K12781. Sort Words and Numbers

    ID: 23767 Type: Default 1000ms 256MiB

Sort Words and Numbers

Sort Words and Numbers

Given a string of words and integers separated by spaces, sort the integers in ascending order first, followed by the words sorted in lexicographical order. In other words, the task is to split the input into two categories: numbers (non-negative integers) and words. Then, the numbers should be sorted in numerical order and the words in alphabetical order. Finally, the result is obtained by concatenating the sorted numbers (converted back to strings) followed by the sorted words.

The process can be mathematically expressed as follows:

$$\text{result} = \text{join}(\text{sorted}(\{n_i\}), \text{sorted}(\{w_j\})) $$

where ({n_i}) are the integers and ({w_j}) are the words. This problem tests your ability to perform string manipulation, sorting, and proper input-output handling.

inputFormat

Input is provided via standard input (stdin) as a single line containing words and integers separated by spaces. For example:

apple 34 3 banana 7

outputFormat

Output a single line to standard output (stdout). The output should be a space-separated string where all integers are sorted in ascending order and appear first, followed by words sorted in lexicographical (alphabetical) order.## sample

apple 34 3 banana 7
3 7 34 apple banana