Reverse Words in a String
All submissions for this problem are available.
Given a string, reverse the string word by word.Here's the format of the Input.
where T is the number of the strings, and S1, S2, etc. are the strings containing words to be reversed.
Each input is on a new line, and can be read with subsequent
input()statements in Python (or any alternative command for other languages that reads from the Standard Input or STDIN).
For each String received, immediately output the result to the STDOUT or Standard Output (eg. using
print()in Python), each on a new line.
Here's a Sample Input.
3 the sky is blue hello world! a good example
Here's the Output.
blue is sky the world! hello example good a
- A word is defined as a sequence of non-space characters.
- Input string may contain leading or trailing spaces. However, your reversed string should not contain leading or trailing spaces.
- You need to reduce multiple spaces between two words to a single space in the reversed string.
|Time Limit:||5 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, JS|
Fetching successful submissions