#K64357. Reverse Words in a String
Reverse Words in a String
Reverse Words in a String
Given a non-empty string s
, reverse each word in the string while keeping the word order the same. A word is defined as a maximal substring consisting of non-space characters. The reversal applies to each word independently.
The task is formalized as follows:
Given a string \(s\), return a new string where every word in \(s\) is replaced by its reversed version. The words in the returned string should appear in the same order as in \(s\).
Example:
Input: "Hello World"
Output: "olleH dlroW"
Note: The input is provided via standard input (stdin) and the output should be written to standard output (stdout).
inputFormat
The input consists of a single line containing the string s
which may include spaces and punctuation. The input is read from standard input (stdin).
outputFormat
Output the transformed string in which each word is reversed while the word order remains the same. The output should be printed to standard output (stdout).
## sampleHello
olleH