Reverse Characters Inside Each Sentence Word. Reverse the characters of every word in s while keeping the words in their original order and every separating space in place.
### Problem
Reverse the characters of every word in s while keeping the words in their original order and every separating space in place. Printable ASCII characters belong to words unless they are the single separating space.
```cpp
class Solution {
public:
string reverseWords(string s);
};
```
### Examples
**Example 1:**
```text
s = "blue sky"
Output: "eulb yks"
Explanation: The two word positions are unchanged.
```
**Example 2:**
```text
s = "go! now"
Output: "!og won"
Explanation: Punctuation is reversed as part of its word.
```
### Constraints
- Sentence length: 1..50000 printable ASCII characters. At least one word is present. A single space separates successive words; no space precedes the first or follows the last.
### Clarifying Questions
Preserve punctuation and spaces while reversing only characters within each word.
```hint Read the boundary condition
What are the exact start and end positions of one word?
```
### Contract considerations
Preserve punctuation and spaces while reversing only characters within each word.
Overview: Reverse Characters Inside Each Sentence Word. Reverse the characters of every word in s while keeping the words in their original order and every separating space in place.
Reverse the characters of every word in s while keeping the words in their original order and every separating space in place. Printable ASCII characters belong to words unless they are the single separating space.
class Solution {
public:
string reverseWords(string s);
};
Examples
Example 1:
s = "blue sky"
Output: "eulb yks"
Explanation: The two word positions are unchanged.
Example 2:
s = "go! now"
Output: "!og won"
Explanation: Punctuation is reversed as part of its word.
Constraints
Sentence length: 1..50000 printable ASCII characters. At least one word is present. A single space separates successive words; no space precedes the first or follows the last.
Clarifying Questions Guidance
Preserve punctuation and spaces while reversing only characters within each word.
Contract considerations
Preserve punctuation and spaces while reversing only characters within each word.