#K40417. Reverse Words in a String
Reverse Words in a String
Reverse Words in a String
Given an input string s, your task is to reverse the order of the words in the string. A word is defined as a sequence of non-space characters. The input string may contain leading or trailing spaces and multiple spaces between words. Your program should output the words in reverse order, concatenated by a single space.
For example, given the string "the sky is blue", the output should be "blue is sky the".
Note:
- If the input is an empty string or only contains spaces, the output should be an empty string.
The transformation can be summarized using the following formula in \( \LaTeX \):
\[ \text{Output} = \text{join}(\text{reverse}(\text{filter}(\text{split}(s, ' '), \text{non-empty})), ' ') \]
inputFormat
The input consists of a single line containing a string s.
The string may include leading, trailing, or multiple spaces between words.
outputFormat
Output a single line containing the words from the input string in reverse order, separated by a single space.
## samplethe sky is blue
blue is sky the