#C14380. Reverse Words with Preserved Spaces

    ID: 44023 Type: Default 1000ms 256MiB

Reverse Words with Preserved Spaces

Reverse Words with Preserved Spaces

Given a string representing a sentence, reverse the order of the words while preserving the exact spacing between words. The challenge is to maintain the landmark spacing, such as multiple spaces between words, leading spaces, and trailing spaces.

Consider the sentence \( S \). Your task is to produce a new string where the words of \( S \) are reversed, yet the spacing remains identical. For example, when \( S = \texttt{hello world this is a test} \), the output should be \( \texttt{test a is this world hello} \).

inputFormat

The input consists of a single line containing a string \( S \) which may include multiple spaces. The string does not include any newline characters within it.

outputFormat

Output the sentence with the words in reversed order while preserving the exact spacing pattern of the original input.

## sample
hello world
world hello