TopCoder problem "Sentence" used in SRM 21 (Division I Level One , Division II Level One)

Problem Statement

Class name: Sentence
Method name: fix
Parameters: String
Returns: String

Implement a class Sentence, which contains a method fix.  fix returns the
result of a series of transformations on the input string described below.  The
input is a sentence, using only letters and spaces, with a period allowed only
if it is the last character.

*Capitalize the first letter of the first word, if it is not already  (The
first character of the first word is the first non-space character).

*Compress any consecutive spaces into one space and remove any spaces at the
beginning or end of the sentence (remove all spaces before the first non-space
character and after the last non-space character).

*Finally, ensure that there is period at the end of the sentence.  If not,
append a period to the end of the sentence.

Process rules from first to last.  

Here is the method signature (be sure your method is public):
String fix(String input)

input is at most 50 characters, contains letters, spaces, and possibly ends
with a period.  It contains at least one letter.

"This is correct." returns "This is correct."
"this  is  wrong" returns "This is wrong."
"   another test    " returns "Another test."
"   another test   ." returns "Another test ."
"         a       ." returns "A ."


Method signature:String fix(String param0)
(be sure your method is public)

Problem url:

Problem stats url:




Problem categories: