#C336. Reverse Words in a Sentence

    ID: 46778 Type: Default 1000ms 256MiB

Reverse Words in a Sentence

Reverse Words in a Sentence

Given a sentence, your task is to reverse every word in the sentence while keeping the words and their original spacing in place. More formally, let ( S ) be a string consisting of words and spaces. For each maximal substring ( w ) of non-space characters in ( S ), replace it by the string ( w^R ) which is the reversal of ( w ). The positions and sequences of the space characters must remain unchanged.

For example, if the input is Hello World, the output should be olleH dlroW.

Note that multiple consecutive spaces should be preserved exactly as they appear in the input.

inputFormat

Input is provided via stdin as a single line string representing the sentence. The sentence may contain letters, punctuation, and multiple consecutive space characters.

outputFormat

Output the transformed string to stdout where every word is reversed while the spacing remains unchanged.## sample

Hello World
olleH dlroW