TopcoderArchive
SRM9 Aug 2001
SRM 21

Sentence

Problem statement, definition, constraints, and public examples.

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.

Examples:
"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 ."

Definition

Class:
Sentence
Method:
fix
Parameters:
String
Returns:
String
Method signature:
String fix(String param0)
(be sure your method is public)

Constraints

    Examples

      No public sample cases were explicitly marked for this problem in the original data.

      Back to all problems