#K34647. Reverse the Words in a Sentence Preserving Spaces
Reverse the Words in a Sentence Preserving Spaces
Reverse the Words in a Sentence Preserving Spaces
You are given a sentence as input, and your task is to output the sentence with the order of the words reversed.
A word is defined as a maximal substring composed of non-space characters. All spaces (including leading, trailing, and multiple spaces between words) must be preserved exactly in their corresponding positions.
In other words, if the input string is ( s ), you need to compute a new string ( t ) such that if you split ( s ) by the space character (i.e., using the delimiter ' '), reverse the order of the tokens, and then join them with a single space, the result is ( t ).
inputFormat
The input consists of a single line containing the sentence. The sentence may include leading, trailing, and multiple spaces between words.
outputFormat
Output a single line which is the original sentence with the order of the words reversed while preserving all the original spaces.## sample
The quick brown fox
fox brown quick The