#K73187. Reverse Words Preserving Punctuation

    ID: 33920 Type: Default 1000ms 256MiB

Reverse Words Preserving Punctuation

Reverse Words Preserving Punctuation

In this problem, you are given a sentence consisting of words separated by spaces. For each word, you must reverse the order of its alphabetic characters while leaving punctuation marks and other non-alphabetic characters in their original positions.

More formally, for each word, let ( W = w_0w_1...w_{n-1} ) denote its characters. For all indices ( i ) such that (w_i) is a letter (i.e. matches the regular expression [a-zA-Z]), reverse the ordering of these letters while keeping the other characters fixed in their respective positions.

Note: A word is defined as a maximal substring separated by spaces. The final output should contain the transformed words separated by a single space.

inputFormat

Input is provided from standard input (stdin) as a single line containing the sentence. The sentence may include letters, digits, punctuation marks, and special characters.

outputFormat

Output the transformed sentence to standard output (stdout). Each word in the sentence should have its alphabetic characters reversed while all non-alphabetic characters remain at their original positions.## sample

hello world!
olleh dlrow!