#C14855. Reverse the Words
Reverse the Words
Reverse the Words
You are given a string that may contain multiple spaces between words. Your task is to reverse the order of the words in the input string and output the resulting string with a single space separating the words. Note that any extra spaces at the beginning or end of the input should be ignored.
For example, given the input: Hello there how are you
, the output should be you are how there Hello
.
The mathematical description of the transformation is as follows:
$$\text{output} = \text{join}(\text{reverse}(\text{split}(\text{input},\ \text{whitespace})),\ ' ') $$This means that you first split the input string into words by whitespace, reverse the resulting list, and then join the list back into a single string with a single space between each word.
inputFormat
The input consists of a single line of text, which may contain leading, trailing, or multiple spaces between words.
Input Format:
A single line containing the string
outputFormat
Print the string after reversing the order of the words. The output should not have any leading or trailing spaces and must have a single space between consecutive words.
Output Format:
The modified string with words in reversed order## sample
Hello
Hello