← 返回 microsoft 的题目列表Reverse Words in a String with Original Position Maintenance
类型:online_judge
Problem Description
Given a string, you need to reverse the words but keep the position of non-letter characters unchanged. For example, given the input string "a red, a work:", the output should be "work a, red a:". Here, the position of letters and commas remain unchanged.
Input
A string containing multiple words and possible punctuation marks. It is guaranteed that it contains at least one letter character.
Output
A string with reversed words but with the positions of non-letter characters unchanged.
Test Cases
Input: "a red, a work:" Output: "work a, red a:"
Input: "Hello, World!" Output: "World, Hello!"
Input: "This is a test." Output: "test is a This."
Input: "No, it is not." Output: "not, it is No."
Input: "Single-word!" Output: "Single-word!"
Example
Input
a red, a work: