#C12322. Reverse Words
Reverse Words
Reverse Words
Given a sentence, reverse the order of its words while preserving all punctuation and spacing. For example, if the input is Hello, world! This is a test.
, the output should be test. a is This world! Hello,
.
Pay special attention to leading, trailing, and multiple spaces between words. The approach is to split the sentence into tokens, where each token is either a contiguous sequence of whitespace characters or non-whitespace characters, and then reverse the sequence.
inputFormat
Input is read from stdin as a single line containing the sentence. The sentence may include punctuation and multiple spaces.
outputFormat
Output to stdout the sentence with the order of its tokens reversed (words and spaces maintain their original form).## sample
Hello, world! This is a test.
test. a is This world! Hello,