#K69927. Reverse Words in a Sentence
Reverse Words in a Sentence
Reverse Words in a Sentence
You are given T test cases. Each test case contains one sentence. Your task is to reverse the order of the words in the given sentence. The words in the sentence are separated by spaces. Even if a sentence contains a single word or is empty, you should output it as is.
For example, given the sentence "Hello World", the output should be "World Hello".
The problem can be mathematically expressed as follows:
Given a sentence \(S = w_1\ w_2\ \ldots\ w_n\), produce \(S' = w_n\ w_{n-1}\ \ldots\ w_1\).
inputFormat
The input is read from STDIN and consists of:
- An integer T denoting the number of test cases.
- T lines, each containing a single sentence. A sentence is a sequence of words separated by spaces and may be empty.
outputFormat
For each test case, output the sentence with the order of its words reversed. Each result should be printed on a new line to STDOUT.
## sample3
Hello World
The quick brown fox
Coding is fun
World Hello
fox brown quick The
fun is Coding
</p>