#C10616. Reverse the Order of Words

    ID: 39841 Type: Default 1000ms 256MiB

Reverse the Order of Words

Reverse the Order of Words

Given an input string s, reverse the order of the words while keeping the characters in each word in the original order. For example, if s is "this is a test", then the output should be "test a is this". Note that the string may contain multiple consecutive spaces which should be preserved in their relative positions.

Formally, if the input string is represented as:

$$s = w_1 \; d_1 \; w_2 \; d_2 \; \ldots \; d_{n-1} \; w_n, $$

where each wi is a word and each di is a sequence of one or more space characters, then the output should be:

wn  dn1    d1  w1.w_n \; d_{n-1} \; \ldots \; d_1 \; w_1.

Your task is to implement a program that reads a single line from standard input and outputs the transformed string.

inputFormat

A single line containing the string s to be processed. The string may include spaces and can be empty.

outputFormat

Output a single line with the words in the string reversed in order. All spaces, including multiple consecutive spaces, must be preserved.## sample

this is a test
test a is this