#C14541. Reverse the Words in a Sentence
Reverse the Words in a Sentence
Reverse the Words in a Sentence
Given an input string representing a sentence, your task is to reverse the order of the words. A word is defined as a sequence of non-space characters, and words in the input are separated by one or more spaces. Extra spaces should be ignored in the final output, and the returned result must have a single space between words.
For example, if the input is "python is amazing", then the output should be "amazing is python".
Please note:
- The input might contain leading or trailing spaces, or even multiple spaces between words.
- An empty input string should return an empty output string.
inputFormat
The input is provided via standard input (stdin) as a single line containing the sentence.
outputFormat
Output the sentence with the word order reversed. The words should be separated by a single space, and no extra spaces should appear at the beginning or end of the output.
## samplehello
hello