#C676. Sort Words While Preserving Numbers

    ID: 50555 Type: Default 1000ms 256MiB

Sort Words While Preserving Numbers

Sort Words While Preserving Numbers

You are given a string consisting of words and numbers separated by spaces. Your task is to sort only the words (alphabetic strings) in ascending order (using case‐insensitive comparison) while keeping the numbers in their original positions.

For example, given the input dog 23 cat 56 apple 12, the sorted order for words (dog, cat, apple) is apple, cat, dog, so the output should be apple 23 cat 56 dog 12.

The formula defining the order for words can be expressed in LaTeX format as:

\( \text{Sort}(W) = \{w_1, w_2, \dots, w_n\} \text{ such that } w_i \leq w_j \text{ for all } i < j \)

inputFormat

The input consists of a single line containing a sequence of tokens separated by spaces. Each token is either a word (consisting of only alphabetic characters) or a number (consisting of digits only).

outputFormat

Output a single line where the words have been sorted in ascending (case-insensitive) order while the numbers remain in their original positions.

## sample
apple banana cherry
apple banana cherry

</p>