The harbor control tower at Meridian Port broadcasts departure announcements to ships over an aging relay line. The relay hardware has one quirk that everyone on the docks has learned to expect: it always retransmits the words of a message in reverse order, while leaving the letters inside each word completely untouched, and it always separates the retransmitted words with exactly one space and no leading or trailing space. You are given the original announcement exactly as the harbor operator typed it. Simulate what the relay line broadcasts to the ships.
A single line containing the announcement s.
s is non-empty, contains no leading or trailing spaces, and consists of one or more words separated by exactly one space.Print the relayed announcement on a single line: the same words, in reverse order, joined by exactly one space each, with no leading or trailing space.
1 <= length of s <= 100000s consists of printable ASCII characters (codes 33-126) and the space character onlyExample 1
Input
now boarding pier seven
Expected
seven pier boarding now
Explanation
The words are ["now","boarding","pier","seven"]. The relay reverses their order to ["seven","pier","boarding","now"], which joined with single spaces gives "seven pier boarding now".
Example 2
Input
all ashore
Expected
ashore all
Explanation
The words are ["all","ashore"]. Reversing their order gives ["ashore","all"], printed as "ashore all".
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →