Statistics

Problem Statement for "SuperSort"

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

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

  1. "The big, brown dog ran down the street!"

    Returns: "The big, brown dog down ran street the!"

  2. "This is the first sentence of the paragraph."

    Returns: "This first is of paragraph sentence the the."

  3. "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."

  4. "What is this?"

    Returns: "What is this?"

  5. "? . , ! "

    Returns: "? . , ! "

  6. " "

    Returns: " "

  7. "faecdb"

    Returns: "faecdb"

  8. "a A b B c C d D e E"

    Returns: "A B C D E a b c d e"

  9. ".a."

    Returns: ".a."

  10. " bb "

    Returns: " bb "

  11. " . ? .bcb"

    Returns: " . ? .bcb"

  12. "z.yy.xxx...ww.uuuu tt"

    Returns: "tt.uuuu.ww...xxx.yy z"

  13. "aA Aa bB Bb.? !.Cc cC"

    Returns: "Aa Bb Cc aA.? !.bB cC"

  14. ".The The.The,The?The!The"

    Returns: ".The The.The,The?The!The"

  15. ".., ??!. ,,, , "

    Returns: ".., ??!. ,,, , "

  16. "a . b c e f , ! g ? g"

    Returns: "a . b c e f , ! g ? g"

  17. ".d....ef......ag...adf....d...sd..f."

    Returns: ".adf....ag......d...d....ef...f..sd."

  18. "defg cdef bcde abde.edba edcb fedc gfed"

    Returns: "abde bcde cdef defg.edba edcb fedc gfed"

  19. "defg cdef bcde abde.edba edcb fedc gfed"

    Returns: "abde bcde cdef defg.edba edcb fedc gfed"

  20. " z.w!xx,,,yy aaaaa fffff adslfjasdf fdjla"

    Returns: " aaaaa.adslfjasdf!fdjla,,,fffff w xx yy z"

  21. "jkld,ajkfla,,,fkaldfjkal,,a,dd..adsf.fjdl..adsfa.a"

    Returns: "a,a,,,adsf,,adsfa,ajkfla..dd.fjdl..fkaldfjkal.jkld"

  22. "lk kld adf jkl, adsf. adsf! fjdkls? alsdfj ?adfj??"

    Returns: "adf adfj adsf adsf, alsdfj. fjdkls! jkl? kld ?lk??"

  23. "ZZw,!ZZt ZZr,,ZZm!!ZZl . ZZj??ZZk ZZc"

    Returns: "ZZc,!ZZj ZZk,,ZZl!!ZZm . ZZr??ZZt ZZw"

  24. "czzz.bbbbbbbbbb.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

    Returns: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.bbbbbbbbbb.czzz"

  25. "Able, Alex abhors aggression!"

    Returns: "Able, Alex abhors aggression!"

  26. " A"

    Returns: " A"

  27. "A..............................."

    Returns: "A..............................."

  28. ".AA. ,CCC, !FFFFF! ?AAA?"

    Returns: ".AA. ,AAA, !CCC! ?FFFFF?"

  29. "B!!!!!!!!!!!!!!!!!!!!!!!A"

    Returns: "A!!!!!!!!!!!!!!!!!!!!!!!B"

  30. "....vv..A A,,XX,,,,"

    Returns: "....A..A XX,,vv,,,,"

  31. "?What did the old man say"

    Returns: "?What did man old say the"

  32. "a"

    Returns: "a"

  33. "."

    Returns: "."

  34. "a,a"

    Returns: "a,a"

  35. "q"

    Returns: "q"

  36. "? af . , A ! df "

    Returns: "? A . , af ! df "

  37. "hvala"

    Returns: "hvala"

  38. " 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"

    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"

  39. " !ss!!b ! !"

    Returns: " !b!!ss ! !"

  40. "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

    Returns: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"

  41. " !! t h Tes a Word"

    Returns: " !! Tes Word a h t"


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: