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:
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
- Class:
- SuperSort
- Method:
- wordSort
- Parameters:
- String
- Returns:
- String
- Method signature:
- String wordSort(String sentence)
- (be sure your method is public)
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
"The big, brown dog ran down the street!"
Returns: "The big, brown dog down ran street the!"
"This is the first sentence of the paragraph."
Returns: "This first is of paragraph sentence the the."
"t.d,a!f?g.b,q!i?p.h,s!u?m.l,e!v?y.c,j!w?k.n,x!o?r."
Returns: "a.b,c!d?e.f,g!h?i.j,k!l?m.n,o!p?q.r,s!t?u.v,w!x?y."
"What is this?"
Returns: "What is this?"
"? . , ! "
Returns: "? . , ! "
" "
Returns: " "
"faecdb"
Returns: "faecdb"
"a A b B c C d D e E"
Returns: "A B C D E a b c d e"