#C9822. Reverse Characters in Each Word
Reverse Characters in Each Word
Reverse Characters in Each Word
Given a string s
that consists of alphabetical characters and spaces, reverse the characters in each word while keeping the spaces in their original positions. For example, if the input is "hello world", then the output should be "olleh dlrow". Note that any leading, trailing, or multiple consecutive spaces should be preserved in the output.
More formally, if the input string is represented as s and is composed of a sequence of words separated by space characters, you need to compute a new string t such that for each maximal contiguous block of non-space characters w in s, its corresponding block in t is \(w^R\) (i.e. the reversal of w).
Examples:
- Input: "hello"; Output: "olleh"
- Input: "code assessment"; Output: "edoc tnemssessa"
- Input: "reverse these words"; Output: "esrever eseht sdrow"
- Input: "a b c"; Output: "a b c"
inputFormat
The input is provided via standard input (stdin) as a single line containing a string s
.
Note: The string may include leading, trailing, or multiple consecutive spaces.
outputFormat
Output the transformed string to standard output (stdout) where each word in the input has its characters reversed, while the spaces remain in the same positions.
## samplehello
olleh