#C14998. Reverse Words in a Sentence

    ID: 44708 Type: Default 1000ms 256MiB

Reverse Words in a Sentence

Reverse Words in a Sentence

Given a sentence, reverse the order of words. Words are defined as sequences of non-space characters. The sentence may have leading or trailing spaces, and there might be multiple spaces between words. The output should be the words in reverse order, separated by a single space. If the input is an empty string, the output should also be an empty string.

Note: Ensure that your solution reads input from standard input (stdin) and writes output to standard output (stdout).

Formally, if the input sentence is represented as a string \( S \), and its words are \( w_1, w_2, \dots, w_n \), then the output should be the string \( w_n \ w_{n-1} \ \dots \ w_1 \).

inputFormat

A single line containing the sentence to process. The sentence may include multiple spaces between words as well as leading or trailing spaces.

outputFormat

A single line with the words of the input sentence in reversed order, separated by a single space. If the input is empty, output an empty string.

## sample
the sky is blue
blue is sky the