#K44122. Reverse Each Word in String with Preserved Spaces
Reverse Each Word in String with Preserved Spaces
Reverse Each Word in String with Preserved Spaces
You are given a string (s) that consists of words separated by spaces. Your task is to reverse each word individually while preserving the order of the words and all the spaces in the string.
For example, if (s = \texttt{Hello World}), then the output should be (\texttt{olleH dlroW}).
inputFormat
The input is provided via standard input as a single string. The string may contain multiple spaces between words, as well as leading or trailing spaces.
outputFormat
Output the transformed string where each word is reversed individually, while all spaces (including multiple, leading, or trailing) are preserved in their original positions.## sample
Hello World
olleH dlroW