Problem Statement | |||||||||||||
| A sentence is composed of words, spaces and punctuation. For this problem, words are maximal contiguous strings of letters. Given a sentence, sort the words in the sentence while preserving the spaces and punctuation. Sorting is case sensitive, so uppercase letters precede lowercase letters. Return the newly constructed sentence.
Example: "The big, brown dog ran down the street!"Returns: "The big, brown dog down ran street the!"Observe the space and punctuation preservation between the original sentence and the resulting sentence. | |||||||||||||
Definition | |||||||||||||
| |||||||||||||
Notes | |||||||||||||
| - | Watch out for multiple consecutive spaces (they should be preserved). | ||||||||||||
Constraints | |||||||||||||
| - | sentence will contain between 1 and 50 characters, inclusive. | ||||||||||||
| - | Each character in sentence will be either a letter ('a'-'z', 'A'-'Z'), ' ', '.', ',', '!' or '?'. | ||||||||||||
Examples | |||||||||||||
| 0) | |||||||||||||
| |||||||||||||
| 1) | |||||||||||||
| |||||||||||||
| 2) | |||||||||||||
| |||||||||||||
| 3) | |||||||||||||
| |||||||||||||
| 4) | |||||||||||||
| |||||||||||||
| 5) | |||||||||||||
| |||||||||||||
| 6) | |||||||||||||
| |||||||||||||
| 7) | |||||||||||||
| |||||||||||||