#K39947. Reverse Words Individually
Reverse Words Individually
Reverse Words Individually
Given a string, the task is to reverse each word individually while preserving the original word order and spacing. A word is defined as a sequence of non-space characters. The spacing (including multiple consecutive spaces) and punctuation should remain in their original positions after the reversal of each valid word.
For example, if the input string is "Hello world!", reversing each word will produce "olleH !dlrow".
Note: The reversal must only affect the characters of the words, leaving spaces and punctuation untouched.
inputFormat
The input consists of a single line containing a string s (which may include spaces, punctuation, and may be empty). The string can be arbitrarily long.
Input Format:
( s )
outputFormat
Output the transformed string where each word has been individually reversed while preserving the original spacing and punctuation.
Output Format:
The resulting string.
## sampleHello world!
olleH !dlrow