You are given a string ‘STR’ containing space-separated words. A word is a sequence of non-space characters. Your task is to reverse the order of words in ‘STR’.
‘STR’ = “when in doubt use brute force”
The reverse order of words in ‘STR’ is: “force brute use doubt in when”.
1. ‘STR’ does not contain any leading or trailing spaces.
2. The words are always separated by a single whitespace character.
The first line of input contains an integer ‘T’ which denotes the number of test cases. Then, the ‘T’ test cases follow.
The first line and only line of each test case contain a single string ‘STR’.
For every test case, return a string with the reverse orders of words as ‘STR’.
You do not need to print anything; it has already been taken care of. Just implement the function.
1 <= T <= 100
1 <= Length of ‘STR’ <= 10^3
The string ‘STR’ contains only ‘a-z’ and whitespace characters.
Time limit: 1 second
Sample input 1:
when all else fails reboot
Sample output 1:
reboot fails else all when
Explanation of sample input 1:
Test Case 1:
‘STR’ = “when all else fails reboot”
The reverse order of words in ‘STR’ is: “reboot fails else all when”.
Test Case 2:
Sample input 2:
no code has zero defects
whitespace is never white
Sample output 2:
defects zero has code no
white never is whitespace