#C1356. Reverse Words in a String
Reverse Words in a String
Reverse Words in a String
You are given a string s
that consists of words separated by spaces. Your task is to reverse the characters in each word while preserving the original order of the words and the spaces exactly as they appear. A word is defined as a contiguous sequence of non-space characters.
For example, given the string "Let's take LeetCode contest", the output should be "s'teL ekat edoCteeL tsetnoc".
Note: The input string may contain multiple spaces between words, and these spaces must be retained in the output.
The reversal for each word is done using the formula:
\[
word_{reversed} = reverse(word)
\]
where reverse(word) denotes the characters of word
in reverse order.
inputFormat
The input consists of a single line string read from stdin. The string may contain spaces and should be processed as it is.
Example Input:
Let's take LeetCode contest
outputFormat
Output a single line string to stdout where the characters of each word have been reversed, while preserving the order of words and spaces.
Example Output:
s'teL ekat edoCteeL tsetnoc## sample
Let's take LeetCode contest
s'teL ekat edoCteeL tsetnoc