#K57112. Reverse Words in a String

    ID: 30349 Type: Default 1000ms 256MiB

Reverse Words in a String

Reverse Words in a String

You are given a string (S) that consists of words separated by spaces. The task is to reverse the order of the words. Note that the string may contain extra spaces at the beginning, at the end, or between words. Your solution should output the words in reverse order with a single space separating them.

inputFormat

The input is provided on the standard input (stdin) as a single line containing the string (S). The string may include leading, trailing, or multiple spaces between words.

outputFormat

Print the string with the words in reverse order on the standard output (stdout). Words must be separated by a single space.## sample

hello world this is a test
test a is this world hello