#C791. Reverse String With Spaces
Reverse String With Spaces
Reverse String With Spaces
You are given a string s that contains letters, spaces, and special characters. Your task is to reverse the characters of the string while keeping the spaces in their original positions. In other words, only the non-space characters should be reversed, while the spaces should remain at the same indices as in the input.
Note: The input may contain leading, trailing, or multiple consecutive spaces. Your solution must handle these cases correctly.
The reversal should follow the algorithm where two pointers traverse the string from both ends. If a pointer encounters a space, it should skip that character and continue. Otherwise, swap the non-space characters.
inputFormat
The input consists of a single line containing the string s. The string may include spaces as well as special characters. Input is provided via standard input (stdin).
outputFormat
Output the modified string after reversing only the non-space characters, keeping spaces in their original positions. The output should be written to standard output (stdout).
## samplehello world
dlrow olleh