


‘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
Use an array ‘ARR’ to store the words in ‘STR’. Traverse the string ‘STR’ and append each word at the end of ‘ARR’. Use the string ‘RES’ to store the answer. Traverse the array ‘ARR’ in reverse and append the words in ‘ARR’ to ‘RES’ followed by a whitespace character.
Reverse the string ‘STR’, so the new string ‘STR’ has the reverse order of words as that of the original string, but the characters in each word are also in reverse order compared to the original string. Now, reverse each word of the new string ‘STR’.
For example:
‘STR’ = “this is a string”
After taking reverse,
‘STR’ = “gnirts a si siht”
Now, take the reverse of each word in ‘str’ to get the answer,
‘STR’ = “string a is this”
Write a function ‘REVERSE_STRING()’ that reverses the string ‘RES’ from position ‘START’ to ‘END’.
‘REVERSE_STRING(string RES, integer START, integer END)’:
Call the function ‘REVERSE_STRING()’ with ‘STR’ as a parameter to reverse the string ‘STR’. After that, call this function for each word of ‘STR’.