A regional courier hub encodes each manifest line before radio transmission: it shuffles the line's words into a random order and appends a single digit from 1 to 9 to every word, recording that word's original 1-indexed position in the line. Given the shuffled, digit-tagged manifest as it arrives over the radio, restore the original line: place each word back at its recorded position and strip the digit, then print the words in order separated by single spaces.
A single line containing the shuffled manifest: one or more words separated by single spaces. Each word consists of English letters (upper- and lower-case) followed by exactly one digit from 1 to 9. There is no leading or trailing whitespace, and exactly one space separates consecutive words.
Print the reconstructed manifest line: the words in their original order, digits removed, separated by single spaces, followed by a newline.
Example 1
Input
is2 sentence4 This1 a3
Expected
This is a sentence
Explanation
Stripping digits and placing by position: position 1 is 'This' (from This1), position 2 is 'is' (from is2), position 3 is 'a' (from a3), position 4 is 'sentence' (from sentence4). Joined: 'This is a sentence'.
Example 2
Input
Myself2 Me1 I4 and3
Expected
Me Myself and I
Explanation
Position 1 is 'Me' (Me1), position 2 is 'Myself' (Myself2), position 3 is 'and' (and3), position 4 is 'I' (I4). Joined: 'Me Myself and I'.
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 →