#K92182. Reverse Words in a Sentence
Reverse Words in a Sentence
Reverse Words in a Sentence
This problem requires you to reverse the order of characters in each word of a given sentence while preserving all whitespace exactly as in the original string. In other words, for each maximal substring consisting of non-space characters (i.e. a "word"), you must reverse the characters, but all spaces (including leading, trailing, and those between words) must remain in their original positions.
For example, given the string:
\( \texttt{The quick brown fox} \)the output should be:
\( \texttt{ehT kciuq nworb xof} \)Please note that if the string contains multiple consecutive spaces, they should be output exactly as they appear in the input.
inputFormat
The input consists of a single line that contains a string s
. This string may include letters, digits, special characters, and spaces. The length of s
is not more than 10,000 characters.
outputFormat
Output a single line representing the modified string in which the characters of each word have been reversed while preserving the original spacing.
## sampleThe quick brown fox
ehT kciuq nworb xof