#C13281. Reverse Words in a Sentence
Reverse Words in a Sentence
Reverse Words in a Sentence
Given a sentence S, reverse the order of its words. The words are defined as sequences of non-space characters. Punctuation marks attached to words should remain with their corresponding words in the reverse order. For instance, if the input is "Hello, World!", the correct output would be "World! Hello,".
More formally, if the sentence is given as a sequence of words \(w_1, w_2, \dots, w_n\) (where punctuation is considered part of a word), then the output should be \(w_n, w_{n-1}, \dots, w_1\).
inputFormat
The input consists of a single line containing the sentence S. The sentence may be empty or contain multiple words separated by spaces.
outputFormat
Output a single line containing the sentence with the order of words reversed. Words must remain unchanged, including any attached punctuation.
## sampleHello World
World Hello