#K6531. Reverse Words in a String
Reverse Words in a String
Reverse Words in a String
Given a string s
, reverse the characters of every word individually while keeping the other characters (such as punctuation, spaces, and digits) in their original positions. Here, a word is defined as a maximal contiguous sequence matching the regular expression \([A-Za-z]+\). This means that only alphabetic characters are reversed, while other symbols remain unchanged.
For example, if the input is "This is a test!", the output should be "sihT si a tset!". Similarly, for the input "Hello, world!", the output should be "olleH, dlrow!". Note that the positions of non-alphabetic characters (like commas, spaces, exclamation marks) are preserved.
Please write a program that reads the input from stdin and outputs the result to stdout.
inputFormat
The input consists of a single line string s
. The string may contain letters, spaces, punctuation marks, digits, or other characters.
outputFormat
Output a single line: the transformed string where each contiguous sequence of alphabet characters has been reversed, while maintaining the original positions of non-alphabet characters.
## sampleThis is a test!
sihT si a tset!