#C14629. Reverse Words Preserving Spaces

    ID: 44299 Type: Default 1000ms 256MiB

Reverse Words Preserving Spaces

Reverse Words Preserving Spaces

Given a sentence as input, reverse the order of the words while keeping the exact sequence of spaces, including multiple spaces between words as well as any leading or trailing spaces. For example, if the input is " hello world ", the output should be " world hello ".

The task is to implement a solution that reads the input from standard input (stdin) and writes the result to standard output (stdout). The solution must preserve the spacing exactly as in the original sentence.

Note: A word is defined as a maximal sequence of non-space characters.

inputFormat

The input consists of a single line containing the sentence. The sentence may contain leading, trailing, or multiple consecutive spaces.

outputFormat

Output the sentence with the words in reverse order, preserving the exact spacing of the original sentence.

## sample
hello world
world hello